| 1 |
.. _exit-codes: |
| 2 |
|
| 3 |
Exit codes |
| 4 |
======================================================== |
| 5 |
|
| 6 |
Running ``pytest`` can result in seven different exit codes: |
| 7 |
|
| 8 |
:Exit code 0: All tests were collected and passed successfully |
| 9 |
:Exit code 1: Tests were collected and run but some of the tests failed |
| 10 |
:Exit code 2: Test execution was interrupted by the user |
| 11 |
:Exit code 3: Internal error happened while executing tests |
| 12 |
:Exit code 4: pytest command line usage error |
| 13 |
:Exit code 5: No tests were collected |
| 14 |
:Exit code 6: Maximum number of warnings exceeded (see :option:`--max-warnings`) |
| 15 |
|
| 16 |
They are represented by the :class:`pytest.ExitCode` enum. The exit codes being a part of the public API can be imported and accessed directly using: |
| 17 |
|
| 18 |
.. code-block:: python |
| 19 |
|
| 20 |
from pytest import ExitCode |
| 21 |
|
| 22 |
.. note:: |
| 23 |
|
| 24 |
If you would like to customize the exit code in some scenarios, specifically when |
| 25 |
no tests are collected, consider using the |
| 26 |
`pytest-custom_exit_code <https://github.com/yashtodi94/pytest-custom_exit_code>`__ |
| 27 |
plugin. |