退出碼

Running pytest can result in six different exit codes:

退出碼 0:

All tests were collected and passed successfully

退出碼 1:

Tests were collected and run but some of the tests failed

退出碼 2:

Test execution was interrupted by the user

退出碼 3:

Internal error happened while executing tests

退出碼 4:

pytest command line usage error

退出碼 5:

No tests were collected

They are represented by the pytest.ExitCode enum. The exit codes being a part of the public API can be imported and accessed directly using:

from pytest import ExitCode

備註

If you would like to customize the exit code in some scenarios, specifically when no tests are collected, consider using the pytest-custom_exit_code plugin.