How to I display why some tests where skipped while using py.test?

PythonUnit TestingPytest

Python Problem Overview


I am using skipIf() from unittest for skipping tests in certain conditions.

@unittest.skipIf(condition), "this is why I skipped them!")

How do I tell py.test to display skipping conditions?

I know that for unittest I need to enable the verbose mode (-v) but the same parameter added to py.test increase the verbosity by still does not display the skip reasons.

Python Solutions


Solution 1 - Python

When you run py.test, you can pass -rsx to report skipped tests.

From py.test --help:

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

Also see this part of the documentation about skipping: http://doc.pytest.org/en/latest/skipping.html

Solution 2 - Python

Short answer:

pytest -rs

This will show extra information of skipped tests.

Detailed answer:

To complement @ToddWilson's answer, the following chars have been added: p and P (2.9.0), a (4.1.0) and A (4.5.0). The detailed information about skipped and xfailed tests is not shown by default in order to avoid cluttering the output. You can use the -r flag among with the following chars:

  • (f)ailed
  • (E)rror
  • (s)kipped
  • (x)failed
  • (X)passed
  • (p)assed
  • (P)assed with output
  • (a)ll except passed (p/P)
  • (A)ll.

Warnings are enabled by default, and the default value is fE.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsorinView Question on Stackoverflow
Solution 1 - PythontoddView Answer on Stackoverflow
Solution 2 - PythonlmiguelvargasfView Answer on Stackoverflow