运行 pytest 时如何抑制所有警告?

KZi*_*vas 6 python testing warnings unit-testing pytest

使用 pytest 运行测试时,某些警告可能会导致问题。可能需要忽略所有警告。我找不到明确的方法来抑制所有警告。

小智 11

您可以运行以下命令:

pytest --disable-warnings
Run Code Online (Sandbox Code Playgroud)


KZi*_*vas 3

这是我找到的解决方案:

pytest -W ignore test_script.py
Run Code Online (Sandbox Code Playgroud)