Skip to content

ExitCode: support custom codes #6022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/_pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ class ExitCode(enum.IntEnum):
#: pytest couldn't find tests
NO_TESTS_COLLECTED = 5

@classmethod
def _missing_(cls, value):
pseudo_member = int.__new__(cls, value)
pseudo_member._name_ = "CUSTOM"
pseudo_member._value_ = value
cls._value2member_map_[value] = pseudo_member
return pseudo_member


def pytest_addoption(parser):
parser.addini(
Expand Down
11 changes: 11 additions & 0 deletions testing/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from _pytest.main import ExitCode


def test_ExitCode():
exc_0 = ExitCode(0)
assert exc_0 == 0
assert repr(exc_0) == "<ExitCode.OK: 0>"

exc_99 = ExitCode(99)
assert exc_99 == 99
assert repr(exc_99) == "<ExitCode.CUSTOM: 99>"