gpt4 book ai didi

python - 如何在 py.test 中显示警告

转载 作者:IT老高 更新时间:2023-10-28 20:40:59 25 4
gpt4 key购买 nike

我刚刚跑了py.test在我的代码上并得到以下输出:

================== 6 passed, 2 pytest-warnings in 40.79 seconds =======================

但是,我看不到 py.test 想要警告我什么。如何打开控制台的警告输出?

py.test --help 为我提供了 --strict 标志:

--strict run pytest in strict mode, warnings become errors.

但是我只想查看输出,而不是让我的测试失败。

我检查了 pytest.orgthis question但他们只关心在 python 中断言警告,而不是显示在命令行上生成的警告。

最佳答案

在这种情况下,pytest-warnings 是为 pytest 和/或其插件生成的警告。这些警告不是为您的代码生成的。为了在报告中列出它们,您需要使用选项 -r w。这是 py.test --help 的一部分:

-r chars              show extra test summary info as specified by chars (f)ailed,
(E)error, (s)skipped, (x)failed, (X)passed
(w)pytest-warnings (a)all.

这将允许在报告中显示警告(记录的顶部)将列出哪些 pytest 插件使用不推荐使用的参数(在我下面的例子中):

...
================================ pytest-warning summary ================================
WI1 /Projects/.tox/py27/lib/python2.7/site-packages/pytest_timeout.py:68 'pytest_runtest_protocol' hook uses deprecated __multicall__ argument
WI1 /Projects/.tox/py27/lib/python2.7/site-packages/pytest_capturelog.py:171 'pytest_runtest_makereport' hook uses deprecated __multicall__ argument
...

关于python - 如何在 py.test 中显示警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33363433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com