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
如何摆脱这些警告?
解决方案
将您的依赖项升级到不会触发警告的版本,或者将其放入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
推荐阅读
- c++ - 我应该将派生类析构函数标记为虚拟/覆盖吗?
- java - Java ScheduledExecutorService 以 100% 运行一个 CPU 内核(但不执行任务)
- swift - 在延迟块中传播异常的正确方法
- javascript - 只需指定字符的开始和结束索引,就可以用标签包围文本范围
- r - Barplot dplyr 汇总值
- javascript - 如何在按钮单击事件 ASP 后调用 javascript 函数
- android - gradle 文件中的版本冲突
- elasticsearch - 如何在一周的时间范围内获取文档
- excel - VBA - 用变量改变 XValues
- haskell - Haskell中的succ:模棱两可的类型变量