Skip to content

Move ExitCode's definition from _pytest.main to _pytest.config #6711

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

Merged
merged 1 commit into from
Feb 11, 2020
Merged
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
2 changes: 1 addition & 1 deletion doc/en/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ ExceptionInfo
pytest.ExitCode
~~~~~~~~~~~~~~~

.. autoclass:: _pytest.main.ExitCode
.. autoclass:: _pytest.config.ExitCode
:members:


Expand Down
2 changes: 1 addition & 1 deletion doc/en/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Running ``pytest`` can result in six different exit codes:
:Exit code 4: pytest command line usage error
:Exit code 5: No tests were collected

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:
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:

.. code-block:: python

Expand Down
28 changes: 25 additions & 3 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" command line options, ini-file and conftest.py processing. """
import argparse
import copy
import enum
import inspect
import os
import shlex
Expand Down Expand Up @@ -61,23 +62,44 @@
hookspec = HookspecMarker("pytest")


class ExitCode(enum.IntEnum):
"""
.. versionadded:: 5.0

Encodes the valid exit codes by pytest.

Currently users and plugins may supply other exit codes as well.
"""

#: tests passed
OK = 0
#: tests failed
TESTS_FAILED = 1
#: pytest was interrupted
INTERRUPTED = 2
#: an internal error got in the way
INTERNAL_ERROR = 3
#: pytest was misused
USAGE_ERROR = 4
#: pytest couldn't find tests
NO_TESTS_COLLECTED = 5


class ConftestImportFailure(Exception):
def __init__(self, path, excinfo):
Exception.__init__(self, path, excinfo)
self.path = path
self.excinfo = excinfo # type: Tuple[Type[Exception], Exception, TracebackType]


def main(args=None, plugins=None) -> "Union[int, _pytest.main.ExitCode]":
def main(args=None, plugins=None) -> Union[int, ExitCode]:
""" return exit code, after performing an in-process test run.

:arg args: list of command line arguments.

:arg plugins: list of plugin objects to be auto-registered during
initialization.
"""
from _pytest.main import ExitCode

try:
try:
config = _prepareconfig(args, plugins)
Expand Down
25 changes: 1 addition & 24 deletions src/_pytest/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
""" core implementation of testing process: init, session, runtest loop. """
import enum
import fnmatch
import functools
import importlib
Expand All @@ -21,6 +20,7 @@
from _pytest.compat import TYPE_CHECKING
from _pytest.config import Config
from _pytest.config import directory_arg
from _pytest.config import ExitCode
from _pytest.config import hookimpl
from _pytest.config import UsageError
from _pytest.fixtures import FixtureManager
Expand All @@ -36,29 +36,6 @@
from _pytest.python import Package


class ExitCode(enum.IntEnum):
"""
.. versionadded:: 5.0

Encodes the valid exit codes by pytest.

Currently users and plugins may supply other exit codes as well.
"""

#: tests passed
OK = 0
#: tests failed
TESTS_FAILED = 1
#: pytest was interrupted
INTERRUPTED = 2
#: an internal error got in the way
INTERNAL_ERROR = 3
#: pytest was misused
USAGE_ERROR = 4
#: pytest couldn't find tests
NO_TESTS_COLLECTED = 5


def pytest_addoption(parser):
parser.addini(
"norecursedirs",
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
from _pytest.capture import SysCapture
from _pytest.compat import TYPE_CHECKING
from _pytest.config import _PluggyPlugin
from _pytest.config import ExitCode
from _pytest.fixtures import FixtureRequest
from _pytest.main import ExitCode
from _pytest.main import Session
from _pytest.monkeypatch import MonkeyPatch
from _pytest.nodes import Collector
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import pytest
from _pytest import nodes
from _pytest.config import Config
from _pytest.main import ExitCode
from _pytest.config import ExitCode
from _pytest.main import Session
from _pytest.reports import CollectReport
from _pytest.reports import TestReport
Expand Down
2 changes: 1 addition & 1 deletion src/pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from _pytest.assertion import register_assert_rewrite
from _pytest.compat import _setup_collect_fakemodule
from _pytest.config import cmdline
from _pytest.config import ExitCode
from _pytest.config import hookimpl
from _pytest.config import hookspec
from _pytest.config import main
Expand All @@ -15,7 +16,6 @@
from _pytest.fixtures import fixture
from _pytest.fixtures import yield_fixture
from _pytest.freeze_support import freeze_includes
from _pytest.main import ExitCode
from _pytest.main import Session
from _pytest.mark import MARK_GEN as mark
from _pytest.mark import param
Expand Down
4 changes: 2 additions & 2 deletions testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import pytest
from _pytest.compat import importlib_metadata
from _pytest.main import ExitCode
from _pytest.config import ExitCode


def prepend_pythonpath(*dirs):
Expand Down Expand Up @@ -412,7 +412,7 @@ def test_a():
def test_report_all_failed_collections_initargs(self, testdir):
testdir.makeconftest(
"""
from _pytest.main import ExitCode
from _pytest.config import ExitCode

def pytest_sessionfinish(exitstatus):
assert exitstatus == ExitCode.USAGE_ERROR
Expand Down
2 changes: 1 addition & 1 deletion testing/python/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import _pytest._code
import pytest
from _pytest.main import ExitCode
from _pytest.config import ExitCode
from _pytest.nodes import Collector


Expand Down
2 changes: 1 addition & 1 deletion testing/test_assertrewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from _pytest.assertion.rewrite import PYC_TAIL
from _pytest.assertion.rewrite import PYTEST_TAG
from _pytest.assertion.rewrite import rewrite_asserts
from _pytest.main import ExitCode
from _pytest.config import ExitCode
from _pytest.pathlib import Path


Expand Down
2 changes: 1 addition & 1 deletion testing/test_cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import py

import pytest
from _pytest.main import ExitCode
from _pytest.config import ExitCode

pytest_plugins = ("pytester",)

Expand Down
2 changes: 1 addition & 1 deletion testing/test_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import pytest
from _pytest import capture
from _pytest.capture import CaptureManager
from _pytest.main import ExitCode
from _pytest.config import ExitCode

# note: py.io capture tests where copied from
# pylib 1.4.20.dev2 (rev 13d9af95547e)
Expand Down
2 changes: 1 addition & 1 deletion testing/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import py

import pytest
from _pytest.config import ExitCode
from _pytest.main import _in_venv
from _pytest.main import ExitCode
from _pytest.main import Session
from _pytest.pytester import Testdir

Expand Down
4 changes: 2 additions & 2 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from _pytest.compat import importlib_metadata
from _pytest.config import _iter_rewritable_modules
from _pytest.config import Config
from _pytest.config import ExitCode
from _pytest.config.exceptions import UsageError
from _pytest.config.findpaths import determine_setup
from _pytest.config.findpaths import get_common_ancestor
from _pytest.config.findpaths import getcfg
from _pytest.main import ExitCode
from _pytest.pathlib import Path


Expand Down Expand Up @@ -1134,7 +1134,7 @@ def test_addopts_from_ini_not_concatenated(self, testdir):
% (testdir.request.config._parser.optparser.prog,)
]
)
assert result.ret == _pytest.main.ExitCode.USAGE_ERROR
assert result.ret == _pytest.config.ExitCode.USAGE_ERROR

def test_override_ini_does_not_contain_paths(self, _config_for_test, _sys_snapshot):
"""Check that -o no longer swallows all options after it (#3103)"""
Expand Down
2 changes: 1 addition & 1 deletion testing/test_conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import py

import pytest
from _pytest.config import ExitCode
from _pytest.config import PytestPluginManager
from _pytest.main import ExitCode
from _pytest.pathlib import Path


Expand Down
2 changes: 1 addition & 1 deletion testing/test_helpconfig.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from _pytest.main import ExitCode
from _pytest.config import ExitCode


def test_version(testdir, pytestconfig):
Expand Down
2 changes: 1 addition & 1 deletion testing/test_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from _pytest.main import ExitCode
from _pytest.config import ExitCode


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion testing/test_mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from unittest import mock

import pytest
from _pytest.main import ExitCode
from _pytest.config import ExitCode
from _pytest.mark import EMPTY_PARAMETERSET_OPTION
from _pytest.mark import MarkGenerator as Mark
from _pytest.nodes import Collector
Expand Down
2 changes: 1 addition & 1 deletion testing/test_pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import types

import pytest
from _pytest.config import ExitCode
from _pytest.config import PytestPluginManager
from _pytest.config.exceptions import UsageError
from _pytest.main import ExitCode
from _pytest.main import Session


Expand Down
2 changes: 1 addition & 1 deletion testing/test_pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import _pytest.pytester as pytester
import pytest
from _pytest.config import ExitCode
from _pytest.config import PytestPluginManager
from _pytest.main import ExitCode
from _pytest.outcomes import Failed
from _pytest.pytester import CwdSnapshot
from _pytest.pytester import HookRecorder
Expand Down
8 changes: 4 additions & 4 deletions testing/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

import _pytest._code
import pytest
from _pytest import main
from _pytest import outcomes
from _pytest import reports
from _pytest import runner
from _pytest.config import ExitCode
from _pytest.outcomes import Exit
from _pytest.outcomes import Failed
from _pytest.outcomes import OutcomeException
Expand Down Expand Up @@ -681,7 +681,7 @@ def test_hello():
def test_pytest_no_tests_collected_exit_status(testdir) -> None:
result = testdir.runpytest()
result.stdout.fnmatch_lines(["*collected 0 items*"])
assert result.ret == main.ExitCode.NO_TESTS_COLLECTED
assert result.ret == ExitCode.NO_TESTS_COLLECTED

testdir.makepyfile(
test_foo="""
Expand All @@ -692,12 +692,12 @@ def test_foo():
result = testdir.runpytest()
result.stdout.fnmatch_lines(["*collected 1 item*"])
result.stdout.fnmatch_lines(["*1 passed*"])
assert result.ret == main.ExitCode.OK
assert result.ret == ExitCode.OK

result = testdir.runpytest("-k nonmatch")
result.stdout.fnmatch_lines(["*collected 1 item*"])
result.stdout.fnmatch_lines(["*1 deselected*"])
assert result.ret == main.ExitCode.NO_TESTS_COLLECTED
assert result.ret == ExitCode.NO_TESTS_COLLECTED


def test_exception_printing_skip() -> None:
Expand Down
2 changes: 1 addition & 1 deletion testing/test_session.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from _pytest.main import ExitCode
from _pytest.config import ExitCode


class SessionTests:
Expand Down
2 changes: 1 addition & 1 deletion testing/test_setuponly.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from _pytest.main import ExitCode
from _pytest.config import ExitCode


@pytest.fixture(params=["--setup-only", "--setup-plan", "--setup-show"], scope="module")
Expand Down
2 changes: 1 addition & 1 deletion testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import py

import pytest
from _pytest.main import ExitCode
from _pytest.config import ExitCode
from _pytest.pytester import Testdir
from _pytest.reports import BaseReport
from _pytest.terminal import _folded_skips
Expand Down
2 changes: 1 addition & 1 deletion testing/test_unittest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gc

import pytest
from _pytest.main import ExitCode
from _pytest.config import ExitCode


def test_simple_unittest(testdir):
Expand Down