Skip to content

Commit 7484e34

Browse files
authored
Merge pull request #6711 from bluetech/mv-exitcode
Move ExitCode's definition from _pytest.main to _pytest.config
2 parents d25123e + d33da07 commit 7484e34

25 files changed

+54
-55
lines changed

doc/en/reference.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ ExceptionInfo
738738
pytest.ExitCode
739739
~~~~~~~~~~~~~~~
740740

741-
.. autoclass:: _pytest.main.ExitCode
741+
.. autoclass:: _pytest.config.ExitCode
742742
:members:
743743

744744

doc/en/usage.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Running ``pytest`` can result in six different exit codes:
3333
:Exit code 4: pytest command line usage error
3434
:Exit code 5: No tests were collected
3535

36-
They are represented by the :class:`_pytest.main.ExitCode` enum. The exit codes being a part of the public API can be imported and accessed directly using:
36+
They are represented by the :class:`_pytest.config.ExitCode` enum. The exit codes being a part of the public API can be imported and accessed directly using:
3737

3838
.. code-block:: python
3939

src/_pytest/config/__init__.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
""" command line options, ini-file and conftest.py processing. """
22
import argparse
33
import copy
4+
import enum
45
import inspect
56
import os
67
import shlex
@@ -61,23 +62,44 @@
6162
hookspec = HookspecMarker("pytest")
6263

6364

65+
class ExitCode(enum.IntEnum):
66+
"""
67+
.. versionadded:: 5.0
68+
69+
Encodes the valid exit codes by pytest.
70+
71+
Currently users and plugins may supply other exit codes as well.
72+
"""
73+
74+
#: tests passed
75+
OK = 0
76+
#: tests failed
77+
TESTS_FAILED = 1
78+
#: pytest was interrupted
79+
INTERRUPTED = 2
80+
#: an internal error got in the way
81+
INTERNAL_ERROR = 3
82+
#: pytest was misused
83+
USAGE_ERROR = 4
84+
#: pytest couldn't find tests
85+
NO_TESTS_COLLECTED = 5
86+
87+
6488
class ConftestImportFailure(Exception):
6589
def __init__(self, path, excinfo):
6690
Exception.__init__(self, path, excinfo)
6791
self.path = path
6892
self.excinfo = excinfo # type: Tuple[Type[Exception], Exception, TracebackType]
6993

7094

71-
def main(args=None, plugins=None) -> "Union[int, _pytest.main.ExitCode]":
95+
def main(args=None, plugins=None) -> Union[int, ExitCode]:
7296
""" return exit code, after performing an in-process test run.
7397
7498
:arg args: list of command line arguments.
7599
76100
:arg plugins: list of plugin objects to be auto-registered during
77101
initialization.
78102
"""
79-
from _pytest.main import ExitCode
80-
81103
try:
82104
try:
83105
config = _prepareconfig(args, plugins)

src/_pytest/main.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
""" core implementation of testing process: init, session, runtest loop. """
2-
import enum
32
import fnmatch
43
import functools
54
import importlib
@@ -21,6 +20,7 @@
2120
from _pytest.compat import TYPE_CHECKING
2221
from _pytest.config import Config
2322
from _pytest.config import directory_arg
23+
from _pytest.config import ExitCode
2424
from _pytest.config import hookimpl
2525
from _pytest.config import UsageError
2626
from _pytest.fixtures import FixtureManager
@@ -36,29 +36,6 @@
3636
from _pytest.python import Package
3737

3838

39-
class ExitCode(enum.IntEnum):
40-
"""
41-
.. versionadded:: 5.0
42-
43-
Encodes the valid exit codes by pytest.
44-
45-
Currently users and plugins may supply other exit codes as well.
46-
"""
47-
48-
#: tests passed
49-
OK = 0
50-
#: tests failed
51-
TESTS_FAILED = 1
52-
#: pytest was interrupted
53-
INTERRUPTED = 2
54-
#: an internal error got in the way
55-
INTERNAL_ERROR = 3
56-
#: pytest was misused
57-
USAGE_ERROR = 4
58-
#: pytest couldn't find tests
59-
NO_TESTS_COLLECTED = 5
60-
61-
6239
def pytest_addoption(parser):
6340
parser.addini(
6441
"norecursedirs",

src/_pytest/pytester.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
from _pytest.capture import SysCapture
3131
from _pytest.compat import TYPE_CHECKING
3232
from _pytest.config import _PluggyPlugin
33+
from _pytest.config import ExitCode
3334
from _pytest.fixtures import FixtureRequest
34-
from _pytest.main import ExitCode
3535
from _pytest.main import Session
3636
from _pytest.monkeypatch import MonkeyPatch
3737
from _pytest.nodes import Collector

src/_pytest/terminal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import pytest
2727
from _pytest import nodes
2828
from _pytest.config import Config
29-
from _pytest.main import ExitCode
29+
from _pytest.config import ExitCode
3030
from _pytest.main import Session
3131
from _pytest.reports import CollectReport
3232
from _pytest.reports import TestReport

src/pytest/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from _pytest.assertion import register_assert_rewrite
77
from _pytest.compat import _setup_collect_fakemodule
88
from _pytest.config import cmdline
9+
from _pytest.config import ExitCode
910
from _pytest.config import hookimpl
1011
from _pytest.config import hookspec
1112
from _pytest.config import main
@@ -15,7 +16,6 @@
1516
from _pytest.fixtures import fixture
1617
from _pytest.fixtures import yield_fixture
1718
from _pytest.freeze_support import freeze_includes
18-
from _pytest.main import ExitCode
1919
from _pytest.main import Session
2020
from _pytest.mark import MARK_GEN as mark
2121
from _pytest.mark import param

testing/acceptance_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import pytest
1010
from _pytest.compat import importlib_metadata
11-
from _pytest.main import ExitCode
11+
from _pytest.config import ExitCode
1212

1313

1414
def prepend_pythonpath(*dirs):
@@ -412,7 +412,7 @@ def test_a():
412412
def test_report_all_failed_collections_initargs(self, testdir):
413413
testdir.makeconftest(
414414
"""
415-
from _pytest.main import ExitCode
415+
from _pytest.config import ExitCode
416416
417417
def pytest_sessionfinish(exitstatus):
418418
assert exitstatus == ExitCode.USAGE_ERROR

testing/python/collect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import _pytest._code
66
import pytest
7-
from _pytest.main import ExitCode
7+
from _pytest.config import ExitCode
88
from _pytest.nodes import Collector
99

1010

testing/test_assertrewrite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from _pytest.assertion.rewrite import PYC_TAIL
2222
from _pytest.assertion.rewrite import PYTEST_TAG
2323
from _pytest.assertion.rewrite import rewrite_asserts
24-
from _pytest.main import ExitCode
24+
from _pytest.config import ExitCode
2525
from _pytest.pathlib import Path
2626

2727

0 commit comments

Comments
 (0)