29

I just ran py.test on my code and got the following output:

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

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 offers me the --strict flag:

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

However I just want to see the output, not make my tests fail.

I checked pytest.org and this question but they are only concerned with asserting warnings in python, not showing warnings generated on the commandline.

4

1 回答 1

34

在这种情况下, pytest-warnings 是为 pytest 和/或其插件生成的警告。这些警告不是为您的代码生成的。为了在报告中列出它们,您需要使用 option -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
...
于 2015-10-27T14:11:14.263 回答