Python 测试时 运行 pytest 警告

Python pytest warnings when running test

我有一个包含我的函数的 myfun.py 文件。
我有一个包含 pytest 测试的 test_myfun.py 文件。

当 运行ning 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) 升级您的软件包,也就是说,如果 html5libscrapy 的最新版本已经修复了这些警告。

2) 在你的 repo 的根目录中创建一个 pytest.ini 文件并给它这些内容,这将使 pytest 忽略 DeprecationWarning

[pytest]
filterwarnings =
    ignore::DeprecationWarning