如何在py.test中显示警告 [英] How to show warnings in py.test
问题描述
我刚刚在我的代码上运行了 py.test
并得到了以下输出:>
I just ran py.test
on my code and got the following output:
================== 6 passed, 2 pytest-warnings in 40.79 seconds =======================
但是,我看不到 py.test
想要警告我的东西.如何打开警告输出到控制台?
However, I cannot see what py.test
would like to warn me about. How can I turn on warning output to the console?
py.test --help
为我提供了-strict
标志:
-strict以严格模式运行pytest,警告变为错误.
--strict run pytest in strict mode, warnings become errors.
但是我只想查看输出,而不是使测试失败.
However I just want to see the output, not make my tests fail.
我检查了 pytest.org 和
I checked pytest.org and this question but they are only concerned with asserting warnings in python, not showing warnings generated on the commandline.
推荐答案
在这种情况下,pytest-warnings是为pytest和/或其插件生成的警告.这些警告不是为您的代码生成的.为了在报告中列出它们,您将需要使用选项 -r w
.这是 py.test --help
的一部分:
In this case, pytest-warnings are warnings which were generated for pytest and/or it's plugins. These warnings were not generated for your code. In order to list them in the report, you will need to use option -r w
. Here is portion of 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插件使用了不推荐使用的参数(在我的情况下为以下提示):
This will allow to show warnings in the report (top portion of the record) will list which pytest plugins use deprecated arguments (in my case bellow):
...
================================ 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
...
这篇关于如何在py.test中显示警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!