Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

No test selected

If you run pytest and it cannot find any tests, for example because you used some selector and no test matched it, then Pytest will exit with exit code 5.

This is considered a failure by every tool, including Jenkins and other CI systems.

On the other hand you won’t see any failed test reported. After all if no tests are run, then none of them fails. This can be confusing. “CI failed, but no test failed and nothing is reported.”

$ pytest -k long test_by_marker.py

============================= test session starts ==============================
platform linux -- Python 3.8.6, pytest-6.1.2, py-1.9.0, pluggy-0.13.1
rootdir: /home/gabor/work/slides/python/examples/pytest, configfile: pytest.ini
plugins: flake8-1.0.6, dash-1.17.0
collected 5 items / 5 deselected

============================ 5 deselected in 0.00s =============================
$ echo $?
5