如何摆脱pytest警告

时间:2020-07-07 01:58:07

标签: python 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

如何摆脱这些警告?

1 个答案:

答案 0 :(得分:0)

要么将依赖项升级到不会触发警告的版本,要么将其放入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