Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show warnings in py.test

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.

like image 297
Sebastian Wozny Avatar asked Oct 27 '15 08:10

Sebastian Wozny


People also ask

How do I check my pytest warnings?

-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. 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):

Which method is used to display a warning message in Python?

Warning messages are displayed by warn() function defined in 'warning' module of Python's standard library.

How do I turn off pytest warnings?

Disabling warnings summary Although not recommended, you can use the --disable-warnings command-line option to suppress the warning summary entirely from the test run output.


1 Answers

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. 

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 ... 
like image 126
sashk Avatar answered Sep 23 '22 02:09

sashk