首页 > 解决方案 > 如何摆脱 pytest 警告

问题描述

当我在 pipenv shell 中运行我的 pytest 时,我得到了这个:

 pipenv shell
Loading .env environment variables…
Launching subshell in virtual environment…

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
bash-3.2$  . /Users/.../.local/share/virtualenvs/kittycapital-UOiJxZhy/bin/activate
(kittycapital) bash-3.2$ python -m pytest
============================================================================================================================= test session starts ==============================================================================================================================
platform darwin -- Python 3.7.7, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
rootdir: /Users/.../kittycapital
plugins: mock-3.1.1
collected 4 items

tests/test_account.py .                                                                                                                                                                                                                                                  [ 25%]
tests/test_pair.py ..                                                                                                                                                                                                                                                    [ 75%]
tests/helpers/test_number_helpers.py .                                                                                                                                                                                                                                   [100%]

=============================================================================================================================== warnings summary ===============================================================================================================================
/Users/.../.local/share/virtualenvs/kittycapital-UOiJxZhy/lib/python3.7/site-packages/urllib3/util/selectors.py:14
  /Users/.../.local/share/virtualenvs/kittycapital-UOiJxZhy/lib/python3.7/site-packages/urllib3/util/selectors.py:14: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working
    from collections import namedtuple, Mapping

/Users/.../.local/share/virtualenvs/kittycapital-UOiJxZhy/lib/python3.7/site-packages/urllib3/_collections.py:2
  /Users/.../.local/share/virtualenvs/kittycapital-UOiJxZhy/lib/python3.7/site-packages/urllib3/_collections.py:2: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working
    from collections import Mapping, MutableMapping

-- Docs: https://docs.pytest.org/en/latest/warnings.html

如何摆脱这些警告?

标签: pythonpytest

解决方案


将您的依赖项升级到不会触发警告的版本,或者将其放入pytest.ini以隐藏该警告:

[pytest]
filterwarnings = ignore:.*Using or importing the ABCs.*is deprecated:DeprecationWarning

请参阅https://docs.pytest.org/en/stable/warnings.html#deprecationwarning-and-pendingdeprecationwarning

或者使用--disable-warnings标志隐藏所有警告:

python -m pytest --disable-warnings

请参阅https://docs.pytest.org/en/stable/warnings.html#disabling-warnings-summary


推荐阅读