运行测试时的python pytest警告

时间:2019-06-21 19:57:07

标签: python warnings pytest

我有一个带有功能的myfun.py文件。
我有一个test_myfun.py个文件,其中包含pytest个测试。

运行pytest test_myfun.py时,测试本身可以正常运行,但pytest会给出警告。

任何建议如何解决这些警告?

=============================== warnings summary ===============================
/home/rene/anaconda3/lib/python3.7/site-packages/html5lib/_trie/_base.py:3
  /home/rene/anaconda3/lib/python3.7/site-packages/html5lib/_trie/_base.py:3: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
    from collections import Mapping

/home/rene/anaconda3/lib/python3.7/site-packages/scrapy/item.py:8
  /home/rene/anaconda3/lib/python3.7/site-packages/scrapy/item.py:8: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
    from collections import MutableMapping

-- Docs: https://docs.pytest.org/en/latest/warnings.html
==================== 11 passed, 2 warnings in 7.47 seconds =====================

版本信息
-Python 3.7.3
-pytest 4.6.2

# packages in environment at /home/rene/anaconda3:
#
# Name                    Version                   Build  Channel
pytest                    4.6.2                    py37_0  
pytest-arraydiff          0.3              py37h39e3cac_0  
pytest-astropy            0.5.0                    py37_0  
pytest-doctestplus        0.3.0                    py37_0  
pytest-openfiles          0.3.2                    py37_0  
pytest-remotedata         0.3.1                    py37_0  
pytest-runner             4.4                        py_0  

1 个答案:

答案 0 :(得分:1)

您有两个选择。

1)升级软件包,也就是说,如果html5libscrapy的最新版本已修复这些警告。

2)在回购的根目录中创建一个pytest.ini文件,并为其提供这些内容,这将使pytest忽略DeprecationWarning

[pytest]
filterwarnings =
    ignore::DeprecationWarning