initial conversion of exit codes to enum

This commit is contained in:
Ronny Pfannschmidt 2019-06-07 12:58:51 +02:00
parent 240828d912
commit 2b92fee1c3
21 changed files with 105 additions and 113 deletions

View File

@ -48,7 +48,7 @@ def main(args=None, plugins=None):
:arg plugins: list of plugin objects to be auto-registered during :arg plugins: list of plugin objects to be auto-registered during
initialization. initialization.
""" """
from _pytest.main import EXIT_USAGEERROR from _pytest.main import ExitCode
try: try:
try: try:
@ -78,7 +78,7 @@ def main(args=None, plugins=None):
tw = py.io.TerminalWriter(sys.stderr) tw = py.io.TerminalWriter(sys.stderr)
for msg in e.args: for msg in e.args:
tw.line("ERROR: {}\n".format(msg), red=True) tw.line("ERROR: {}\n".format(msg), red=True)
return EXIT_USAGEERROR return ExitCode.USAGE_ERROR
class cmdline: # compatibility namespace class cmdline: # compatibility namespace

View File

@ -1,4 +1,5 @@
""" core implementation of testing process: init, session, runtest loop. """ """ core implementation of testing process: init, session, runtest loop. """
import enum
import fnmatch import fnmatch
import functools import functools
import os import os
@ -19,12 +20,15 @@ from _pytest.outcomes import exit
from _pytest.runner import collect_one_node from _pytest.runner import collect_one_node
# exitcodes for the command line # exitcodes for the command line
EXIT_OK = 0
EXIT_TESTSFAILED = 1
EXIT_INTERRUPTED = 2 class ExitCode(enum.IntEnum):
EXIT_INTERNALERROR = 3 OK = 0
EXIT_USAGEERROR = 4 TESTS_FAILED = 1
EXIT_NOTESTSCOLLECTED = 5 INTERRUPTED = 2
INTERNAL_ERROR = 3
USAGE_ERROR = 4
NO_TESTS_COLLECTED = 5
def pytest_addoption(parser): def pytest_addoption(parser):
@ -188,7 +192,7 @@ def pytest_configure(config):
def wrap_session(config, doit): def wrap_session(config, doit):
"""Skeleton command line program""" """Skeleton command line program"""
session = Session(config) session = Session(config)
session.exitstatus = EXIT_OK session.exitstatus = ExitCode.OK
initstate = 0 initstate = 0
try: try:
try: try:
@ -198,13 +202,13 @@ def wrap_session(config, doit):
initstate = 2 initstate = 2
session.exitstatus = doit(config, session) or 0 session.exitstatus = doit(config, session) or 0
except UsageError: except UsageError:
session.exitstatus = EXIT_USAGEERROR session.exitstatus = ExitCode.USAGE_ERROR
raise raise
except Failed: except Failed:
session.exitstatus = EXIT_TESTSFAILED session.exitstatus = ExitCode.TESTS_FAILED
except (KeyboardInterrupt, exit.Exception): except (KeyboardInterrupt, exit.Exception):
excinfo = _pytest._code.ExceptionInfo.from_current() excinfo = _pytest._code.ExceptionInfo.from_current()
exitstatus = EXIT_INTERRUPTED exitstatus = ExitCode.INTERRUPTED
if isinstance(excinfo.value, exit.Exception): if isinstance(excinfo.value, exit.Exception):
if excinfo.value.returncode is not None: if excinfo.value.returncode is not None:
exitstatus = excinfo.value.returncode exitstatus = excinfo.value.returncode
@ -217,7 +221,7 @@ def wrap_session(config, doit):
except: # noqa except: # noqa
excinfo = _pytest._code.ExceptionInfo.from_current() excinfo = _pytest._code.ExceptionInfo.from_current()
config.notify_exception(excinfo, config.option) config.notify_exception(excinfo, config.option)
session.exitstatus = EXIT_INTERNALERROR session.exitstatus = ExitCode.INTERNAL_ERROR
if excinfo.errisinstance(SystemExit): if excinfo.errisinstance(SystemExit):
sys.stderr.write("mainloop: caught unexpected SystemExit!\n") sys.stderr.write("mainloop: caught unexpected SystemExit!\n")
@ -243,9 +247,9 @@ def _main(config, session):
config.hook.pytest_runtestloop(session=session) config.hook.pytest_runtestloop(session=session)
if session.testsfailed: if session.testsfailed:
return EXIT_TESTSFAILED return ExitCode.TESTS_FAILED
elif session.testscollected == 0: elif session.testscollected == 0:
return EXIT_NOTESTSCOLLECTED return ExitCode.NO_TESTS_COLLECTED
def pytest_collection(session): def pytest_collection(session):

View File

@ -19,8 +19,7 @@ from _pytest._io.saferepr import saferepr
from _pytest.assertion.rewrite import AssertionRewritingHook from _pytest.assertion.rewrite import AssertionRewritingHook
from _pytest.capture import MultiCapture from _pytest.capture import MultiCapture
from _pytest.capture import SysCapture from _pytest.capture import SysCapture
from _pytest.main import EXIT_INTERRUPTED from _pytest.main import ExitCode
from _pytest.main import EXIT_OK
from _pytest.main import Session from _pytest.main import Session
from _pytest.monkeypatch import MonkeyPatch from _pytest.monkeypatch import MonkeyPatch
from _pytest.pathlib import Path from _pytest.pathlib import Path
@ -691,7 +690,7 @@ class Testdir:
p = py.path.local(arg) p = py.path.local(arg)
config.hook.pytest_sessionstart(session=session) config.hook.pytest_sessionstart(session=session)
res = session.perform_collect([str(p)], genitems=False)[0] res = session.perform_collect([str(p)], genitems=False)[0]
config.hook.pytest_sessionfinish(session=session, exitstatus=EXIT_OK) config.hook.pytest_sessionfinish(session=session, exitstatus=ExitCode.OK)
return res return res
def getpathnode(self, path): def getpathnode(self, path):
@ -708,11 +707,11 @@ class Testdir:
x = session.fspath.bestrelpath(path) x = session.fspath.bestrelpath(path)
config.hook.pytest_sessionstart(session=session) config.hook.pytest_sessionstart(session=session)
res = session.perform_collect([x], genitems=False)[0] res = session.perform_collect([x], genitems=False)[0]
config.hook.pytest_sessionfinish(session=session, exitstatus=EXIT_OK) config.hook.pytest_sessionfinish(session=session, exitstatus=ExitCode.OK)
return res return res
def genitems(self, colitems): def genitems(self, colitems):
"""Generate all test items from a collection node. """Generate all test items from a collection node.src/_pytest/main.py
This recurses into the collection node and returns a list of all the This recurses into the collection node and returns a list of all the
test items contained within. test items contained within.
@ -841,7 +840,7 @@ class Testdir:
# typically we reraise keyboard interrupts from the child run # typically we reraise keyboard interrupts from the child run
# because it's our user requesting interruption of the testing # because it's our user requesting interruption of the testing
if ret == EXIT_INTERRUPTED and not no_reraise_ctrlc: if ret == ExitCode.INTERRUPTED and not no_reraise_ctrlc:
calls = reprec.getcalls("pytest_keyboard_interrupt") calls = reprec.getcalls("pytest_keyboard_interrupt")
if calls and calls[-1].excinfo.type == KeyboardInterrupt: if calls and calls[-1].excinfo.type == KeyboardInterrupt:
raise KeyboardInterrupt() raise KeyboardInterrupt()

View File

@ -16,11 +16,7 @@ from more_itertools import collapse
import pytest import pytest
from _pytest import nodes from _pytest import nodes
from _pytest.main import EXIT_INTERRUPTED from _pytest.main import ExitCode
from _pytest.main import EXIT_NOTESTSCOLLECTED
from _pytest.main import EXIT_OK
from _pytest.main import EXIT_TESTSFAILED
from _pytest.main import EXIT_USAGEERROR
REPORT_COLLECTING_RESOLUTION = 0.5 REPORT_COLLECTING_RESOLUTION = 0.5
@ -654,17 +650,17 @@ class TerminalReporter:
outcome.get_result() outcome.get_result()
self._tw.line("") self._tw.line("")
summary_exit_codes = ( summary_exit_codes = (
EXIT_OK, ExitCode.OK,
EXIT_TESTSFAILED, ExitCode.TESTS_FAILED,
EXIT_INTERRUPTED, ExitCode.INTERRUPTED,
EXIT_USAGEERROR, ExitCode.USAGE_ERROR,
EXIT_NOTESTSCOLLECTED, ExitCode.NO_TESTS_COLLECTED,
) )
if exitstatus in summary_exit_codes: if exitstatus in summary_exit_codes:
self.config.hook.pytest_terminal_summary( self.config.hook.pytest_terminal_summary(
terminalreporter=self, exitstatus=exitstatus, config=self.config terminalreporter=self, exitstatus=exitstatus, config=self.config
) )
if exitstatus == EXIT_INTERRUPTED: if exitstatus == ExitCode.INTERRUPTED:
self._report_keyboardinterrupt() self._report_keyboardinterrupt()
del self._keyboardinterrupt_memo del self._keyboardinterrupt_memo
self.summary_stats() self.summary_stats()

View File

@ -15,6 +15,7 @@ from _pytest.fixtures import fillfixtures as _fillfuncargs
from _pytest.fixtures import fixture from _pytest.fixtures import fixture
from _pytest.fixtures import yield_fixture from _pytest.fixtures import yield_fixture
from _pytest.freeze_support import freeze_includes from _pytest.freeze_support import freeze_includes
from _pytest.main import ExitCode
from _pytest.main import Session from _pytest.main import Session
from _pytest.mark import MARK_GEN as mark from _pytest.mark import MARK_GEN as mark
from _pytest.mark import param from _pytest.mark import param
@ -57,6 +58,7 @@ __all__ = [
"Collector", "Collector",
"deprecated_call", "deprecated_call",
"exit", "exit",
"ExitCode",
"fail", "fail",
"File", "File",
"fixture", "fixture",

View File

@ -8,8 +8,7 @@ import importlib_metadata
import py import py
import pytest import pytest
from _pytest.main import EXIT_NOTESTSCOLLECTED from _pytest.main import ExitCode
from _pytest.main import EXIT_USAGEERROR
from _pytest.warnings import SHOW_PYTEST_WARNINGS_ARG from _pytest.warnings import SHOW_PYTEST_WARNINGS_ARG
@ -24,7 +23,7 @@ class TestGeneralUsage:
def test_config_error(self, testdir): def test_config_error(self, testdir):
testdir.copy_example("conftest_usageerror/conftest.py") testdir.copy_example("conftest_usageerror/conftest.py")
result = testdir.runpytest(testdir.tmpdir) result = testdir.runpytest(testdir.tmpdir)
assert result.ret == EXIT_USAGEERROR assert result.ret == ExitCode.USAGE_ERROR
result.stderr.fnmatch_lines(["*ERROR: hello"]) result.stderr.fnmatch_lines(["*ERROR: hello"])
result.stdout.fnmatch_lines(["*pytest_unconfigure_called"]) result.stdout.fnmatch_lines(["*pytest_unconfigure_called"])
@ -83,7 +82,7 @@ class TestGeneralUsage:
""" """
) )
result = testdir.runpytest("-s", "asd") result = testdir.runpytest("-s", "asd")
assert result.ret == 4 # EXIT_USAGEERROR assert result.ret == ExitCode.USAGE_ERROR
result.stderr.fnmatch_lines(["ERROR: file not found*asd"]) result.stderr.fnmatch_lines(["ERROR: file not found*asd"])
result.stdout.fnmatch_lines(["*---configure", "*---unconfigure"]) result.stdout.fnmatch_lines(["*---configure", "*---unconfigure"])
@ -229,7 +228,7 @@ class TestGeneralUsage:
""" """
) )
result = testdir.runpytest() result = testdir.runpytest()
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
result.stdout.fnmatch_lines(["*1 skip*"]) result.stdout.fnmatch_lines(["*1 skip*"])
def test_issue88_initial_file_multinodes(self, testdir): def test_issue88_initial_file_multinodes(self, testdir):
@ -247,7 +246,7 @@ class TestGeneralUsage:
""" """
) )
result = testdir.runpytest() result = testdir.runpytest()
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
assert "should not be seen" not in result.stdout.str() assert "should not be seen" not in result.stdout.str()
assert "stderr42" not in result.stderr.str() assert "stderr42" not in result.stderr.str()
@ -290,13 +289,13 @@ class TestGeneralUsage:
sub2 = testdir.mkdir("sub2") sub2 = testdir.mkdir("sub2")
sub1.join("conftest.py").write("assert 0") sub1.join("conftest.py").write("assert 0")
result = testdir.runpytest(sub2) result = testdir.runpytest(sub2)
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
sub2.ensure("__init__.py") sub2.ensure("__init__.py")
p = sub2.ensure("test_hello.py") p = sub2.ensure("test_hello.py")
result = testdir.runpytest(p) result = testdir.runpytest(p)
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
result = testdir.runpytest(sub1) result = testdir.runpytest(sub1)
assert result.ret == EXIT_USAGEERROR assert result.ret == ExitCode.USAGE_ERROR
def test_directory_skipped(self, testdir): def test_directory_skipped(self, testdir):
testdir.makeconftest( testdir.makeconftest(
@ -308,7 +307,7 @@ class TestGeneralUsage:
) )
testdir.makepyfile("def test_hello(): pass") testdir.makepyfile("def test_hello(): pass")
result = testdir.runpytest() result = testdir.runpytest()
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
result.stdout.fnmatch_lines(["*1 skipped*"]) result.stdout.fnmatch_lines(["*1 skipped*"])
def test_multiple_items_per_collector_byid(self, testdir): def test_multiple_items_per_collector_byid(self, testdir):
@ -410,10 +409,10 @@ class TestGeneralUsage:
def test_report_all_failed_collections_initargs(self, testdir): def test_report_all_failed_collections_initargs(self, testdir):
testdir.makeconftest( testdir.makeconftest(
""" """
from _pytest.main import EXIT_USAGEERROR from _pytest.main import ExitCode
def pytest_sessionfinish(exitstatus): def pytest_sessionfinish(exitstatus):
assert exitstatus == EXIT_USAGEERROR assert exitstatus == ExitCode.USAGE_ERROR
print("pytest_sessionfinish_called") print("pytest_sessionfinish_called")
""" """
) )
@ -421,7 +420,7 @@ class TestGeneralUsage:
result = testdir.runpytest("test_a.py::a", "test_b.py::b") result = testdir.runpytest("test_a.py::a", "test_b.py::b")
result.stderr.fnmatch_lines(["*ERROR*test_a.py::a*", "*ERROR*test_b.py::b*"]) result.stderr.fnmatch_lines(["*ERROR*test_a.py::a*", "*ERROR*test_b.py::b*"])
result.stdout.fnmatch_lines(["pytest_sessionfinish_called"]) result.stdout.fnmatch_lines(["pytest_sessionfinish_called"])
assert result.ret == EXIT_USAGEERROR assert result.ret == ExitCode.USAGE_ERROR
@pytest.mark.usefixtures("recwarn") @pytest.mark.usefixtures("recwarn")
def test_namespace_import_doesnt_confuse_import_hook(self, testdir): def test_namespace_import_doesnt_confuse_import_hook(self, testdir):
@ -612,7 +611,7 @@ class TestInvocationVariants:
def test_invoke_with_path(self, tmpdir, capsys): def test_invoke_with_path(self, tmpdir, capsys):
retcode = pytest.main(tmpdir) retcode = pytest.main(tmpdir)
assert retcode == EXIT_NOTESTSCOLLECTED assert retcode == ExitCode.NO_TESTS_COLLECTED
out, err = capsys.readouterr() out, err = capsys.readouterr()
def test_invoke_plugin_api(self, testdir, capsys): def test_invoke_plugin_api(self, testdir, capsys):
@ -1160,7 +1159,7 @@ def test_fixture_mock_integration(testdir):
def test_usage_error_code(testdir): def test_usage_error_code(testdir):
result = testdir.runpytest("-unknown-option-") result = testdir.runpytest("-unknown-option-")
assert result.ret == EXIT_USAGEERROR assert result.ret == ExitCode.USAGE_ERROR
@pytest.mark.filterwarnings("default") @pytest.mark.filterwarnings("default")

View File

@ -4,7 +4,7 @@ import textwrap
import _pytest._code import _pytest._code
import pytest import pytest
from _pytest.main import EXIT_NOTESTSCOLLECTED from _pytest.main import ExitCode
from _pytest.nodes import Collector from _pytest.nodes import Collector
@ -246,7 +246,7 @@ class TestClass:
""" """
) )
result = testdir.runpytest() result = testdir.runpytest()
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
class TestFunction: class TestFunction:
@ -1140,7 +1140,7 @@ def test_unorderable_types(testdir):
) )
result = testdir.runpytest() result = testdir.runpytest()
assert "TypeError" not in result.stdout.str() assert "TypeError" not in result.stdout.str()
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
def test_collect_functools_partial(testdir): def test_collect_functools_partial(testdir):

View File

@ -15,7 +15,7 @@ from _pytest.assertion import util
from _pytest.assertion.rewrite import AssertionRewritingHook from _pytest.assertion.rewrite import AssertionRewritingHook
from _pytest.assertion.rewrite import PYTEST_TAG from _pytest.assertion.rewrite import PYTEST_TAG
from _pytest.assertion.rewrite import rewrite_asserts from _pytest.assertion.rewrite import rewrite_asserts
from _pytest.main import EXIT_NOTESTSCOLLECTED from _pytest.main import ExitCode
def setup_module(mod): def setup_module(mod):
@ -692,7 +692,7 @@ class TestRewriteOnImport:
import test_gum.test_lizard""" import test_gum.test_lizard"""
% (z_fn,) % (z_fn,)
) )
assert testdir.runpytest().ret == EXIT_NOTESTSCOLLECTED assert testdir.runpytest().ret == ExitCode.NO_TESTS_COLLECTED
def test_readonly(self, testdir): def test_readonly(self, testdir):
sub = testdir.mkdir("testing") sub = testdir.mkdir("testing")
@ -792,7 +792,7 @@ def test_rewritten():
pkg = testdir.mkdir("a_package_without_init_py") pkg = testdir.mkdir("a_package_without_init_py")
pkg.join("module.py").ensure() pkg.join("module.py").ensure()
testdir.makepyfile("import a_package_without_init_py.module") testdir.makepyfile("import a_package_without_init_py.module")
assert testdir.runpytest().ret == EXIT_NOTESTSCOLLECTED assert testdir.runpytest().ret == ExitCode.NO_TESTS_COLLECTED
def test_rewrite_warning(self, testdir): def test_rewrite_warning(self, testdir):
testdir.makeconftest( testdir.makeconftest(

View File

@ -6,7 +6,7 @@ import textwrap
import py import py
import pytest import pytest
from _pytest.main import EXIT_NOTESTSCOLLECTED from _pytest.main import ExitCode
pytest_plugins = ("pytester",) pytest_plugins = ("pytester",)
@ -757,7 +757,7 @@ class TestLastFailed:
"* 2 deselected in *", "* 2 deselected in *",
] ]
) )
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
def test_lastfailed_no_failures_behavior_empty_cache(self, testdir): def test_lastfailed_no_failures_behavior_empty_cache(self, testdir):
testdir.makepyfile( testdir.makepyfile(

View File

@ -12,7 +12,7 @@ import py
import pytest import pytest
from _pytest import capture from _pytest import capture
from _pytest.capture import CaptureManager from _pytest.capture import CaptureManager
from _pytest.main import EXIT_NOTESTSCOLLECTED from _pytest.main import ExitCode
# note: py.io capture tests where copied from # note: py.io capture tests where copied from
# pylib 1.4.20.dev2 (rev 13d9af95547e) # pylib 1.4.20.dev2 (rev 13d9af95547e)
@ -361,7 +361,7 @@ class TestLoggingInteraction:
) )
# make sure that logging is still captured in tests # make sure that logging is still captured in tests
result = testdir.runpytest_subprocess("-s", "-p", "no:capturelog") result = testdir.runpytest_subprocess("-s", "-p", "no:capturelog")
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
result.stderr.fnmatch_lines(["WARNING*hello435*"]) result.stderr.fnmatch_lines(["WARNING*hello435*"])
assert "operation on closed file" not in result.stderr.str() assert "operation on closed file" not in result.stderr.str()

View File

@ -7,8 +7,7 @@ import py
import pytest import pytest
from _pytest.main import _in_venv from _pytest.main import _in_venv
from _pytest.main import EXIT_INTERRUPTED from _pytest.main import ExitCode
from _pytest.main import EXIT_NOTESTSCOLLECTED
from _pytest.main import Session from _pytest.main import Session
@ -347,7 +346,7 @@ class TestCustomConftests:
assert result.ret == 0 assert result.ret == 0
result.stdout.fnmatch_lines(["*1 passed*"]) result.stdout.fnmatch_lines(["*1 passed*"])
result = testdir.runpytest() result = testdir.runpytest()
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
result.stdout.fnmatch_lines(["*collected 0 items*"]) result.stdout.fnmatch_lines(["*collected 0 items*"])
def test_collectignore_exclude_on_option(self, testdir): def test_collectignore_exclude_on_option(self, testdir):
@ -364,7 +363,7 @@ class TestCustomConftests:
testdir.mkdir("hello") testdir.mkdir("hello")
testdir.makepyfile(test_world="def test_hello(): pass") testdir.makepyfile(test_world="def test_hello(): pass")
result = testdir.runpytest() result = testdir.runpytest()
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
assert "passed" not in result.stdout.str() assert "passed" not in result.stdout.str()
result = testdir.runpytest("--XX") result = testdir.runpytest("--XX")
assert result.ret == 0 assert result.ret == 0
@ -384,7 +383,7 @@ class TestCustomConftests:
testdir.makepyfile(test_world="def test_hello(): pass") testdir.makepyfile(test_world="def test_hello(): pass")
testdir.makepyfile(test_welt="def test_hallo(): pass") testdir.makepyfile(test_welt="def test_hallo(): pass")
result = testdir.runpytest() result = testdir.runpytest()
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
result.stdout.fnmatch_lines(["*collected 0 items*"]) result.stdout.fnmatch_lines(["*collected 0 items*"])
result = testdir.runpytest("--XX") result = testdir.runpytest("--XX")
assert result.ret == 0 assert result.ret == 0
@ -1172,7 +1171,7 @@ def test_collectignore_via_conftest(testdir, monkeypatch):
ignore_me.ensure("conftest.py").write("assert 0, 'should_not_be_called'") ignore_me.ensure("conftest.py").write("assert 0, 'should_not_be_called'")
result = testdir.runpytest() result = testdir.runpytest()
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
def test_collect_pkg_init_and_file_in_args(testdir): def test_collect_pkg_init_and_file_in_args(testdir):
@ -1234,7 +1233,7 @@ def test_collect_sub_with_symlinks(use_pkg, testdir):
def test_collector_respects_tbstyle(testdir): def test_collector_respects_tbstyle(testdir):
p1 = testdir.makepyfile("assert 0") p1 = testdir.makepyfile("assert 0")
result = testdir.runpytest(p1, "--tb=native") result = testdir.runpytest(p1, "--tb=native")
assert result.ret == EXIT_INTERRUPTED assert result.ret == ExitCode.INTERRUPTED
result.stdout.fnmatch_lines( result.stdout.fnmatch_lines(
[ [
"*_ ERROR collecting test_collector_respects_tbstyle.py _*", "*_ ERROR collecting test_collector_respects_tbstyle.py _*",

View File

@ -10,10 +10,7 @@ from _pytest.config.exceptions import UsageError
from _pytest.config.findpaths import determine_setup from _pytest.config.findpaths import determine_setup
from _pytest.config.findpaths import get_common_ancestor from _pytest.config.findpaths import get_common_ancestor
from _pytest.config.findpaths import getcfg from _pytest.config.findpaths import getcfg
from _pytest.main import EXIT_NOTESTSCOLLECTED from _pytest.main import ExitCode
from _pytest.main import EXIT_OK
from _pytest.main import EXIT_TESTSFAILED
from _pytest.main import EXIT_USAGEERROR
class TestParseIni: class TestParseIni:
@ -189,7 +186,7 @@ class TestConfigCmdlineParsing:
temp_ini_file = normpath(str(temp_ini_file)) temp_ini_file = normpath(str(temp_ini_file))
ret = pytest.main(["-c", temp_ini_file]) ret = pytest.main(["-c", temp_ini_file])
assert ret == _pytest.main.EXIT_OK assert ret == ExitCode.OK
class TestConfigAPI: class TestConfigAPI:
@ -726,7 +723,7 @@ def test_consider_args_after_options_for_rootdir(testdir, args):
@pytest.mark.skipif("sys.platform == 'win32'") @pytest.mark.skipif("sys.platform == 'win32'")
def test_toolongargs_issue224(testdir): def test_toolongargs_issue224(testdir):
result = testdir.runpytest("-m", "hello" * 500) result = testdir.runpytest("-m", "hello" * 500)
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
def test_config_in_subdirectory_colon_command_line_issue2148(testdir): def test_config_in_subdirectory_colon_command_line_issue2148(testdir):
@ -1086,7 +1083,7 @@ class TestOverrideIniArgs:
% (testdir.request.config._parser.optparser.prog,) % (testdir.request.config._parser.optparser.prog,)
] ]
) )
assert result.ret == _pytest.main.EXIT_USAGEERROR assert result.ret == _pytest.main.ExitCode.USAGE_ERROR
def test_override_ini_does_not_contain_paths(self, _config_for_test, _sys_snapshot): 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)""" """Check that -o no longer swallows all options after it (#3103)"""
@ -1175,13 +1172,13 @@ def test_help_and_version_after_argument_error(testdir):
) )
# Does not display full/default help. # Does not display full/default help.
assert "to see available markers type: pytest --markers" not in result.stdout.lines assert "to see available markers type: pytest --markers" not in result.stdout.lines
assert result.ret == EXIT_USAGEERROR assert result.ret == ExitCode.USAGE_ERROR
result = testdir.runpytest("--version") result = testdir.runpytest("--version")
result.stderr.fnmatch_lines( result.stderr.fnmatch_lines(
["*pytest*{}*imported from*".format(pytest.__version__)] ["*pytest*{}*imported from*".format(pytest.__version__)]
) )
assert result.ret == EXIT_USAGEERROR assert result.ret == ExitCode.USAGE_ERROR
def test_config_does_not_load_blocked_plugin_from_args(testdir): def test_config_does_not_load_blocked_plugin_from_args(testdir):
@ -1189,11 +1186,11 @@ def test_config_does_not_load_blocked_plugin_from_args(testdir):
p = testdir.makepyfile("def test(capfd): pass") p = testdir.makepyfile("def test(capfd): pass")
result = testdir.runpytest(str(p), "-pno:capture") result = testdir.runpytest(str(p), "-pno:capture")
result.stdout.fnmatch_lines(["E fixture 'capfd' not found"]) result.stdout.fnmatch_lines(["E fixture 'capfd' not found"])
assert result.ret == EXIT_TESTSFAILED assert result.ret == ExitCode.TESTS_FAILED
result = testdir.runpytest(str(p), "-pno:capture", "-s") result = testdir.runpytest(str(p), "-pno:capture", "-s")
result.stderr.fnmatch_lines(["*: error: unrecognized arguments: -s"]) result.stderr.fnmatch_lines(["*: error: unrecognized arguments: -s"])
assert result.ret == EXIT_USAGEERROR assert result.ret == ExitCode.USAGE_ERROR
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -1219,7 +1216,7 @@ def test_config_blocked_default_plugins(testdir, plugin):
result = testdir.runpytest(str(p), "-pno:%s" % plugin) result = testdir.runpytest(str(p), "-pno:%s" % plugin)
if plugin == "python": if plugin == "python":
assert result.ret == EXIT_USAGEERROR assert result.ret == ExitCode.USAGE_ERROR
result.stderr.fnmatch_lines( result.stderr.fnmatch_lines(
[ [
"ERROR: not found: */test_config_blocked_default_plugins.py", "ERROR: not found: */test_config_blocked_default_plugins.py",
@ -1228,13 +1225,13 @@ def test_config_blocked_default_plugins(testdir, plugin):
) )
return return
assert result.ret == EXIT_OK assert result.ret == ExitCode.OK
if plugin != "terminal": if plugin != "terminal":
result.stdout.fnmatch_lines(["* 1 passed in *"]) result.stdout.fnmatch_lines(["* 1 passed in *"])
p = testdir.makepyfile("def test(): assert 0") p = testdir.makepyfile("def test(): assert 0")
result = testdir.runpytest(str(p), "-pno:%s" % plugin) result = testdir.runpytest(str(p), "-pno:%s" % plugin)
assert result.ret == EXIT_TESTSFAILED assert result.ret == ExitCode.TESTS_FAILED
if plugin != "terminal": if plugin != "terminal":
result.stdout.fnmatch_lines(["* 1 failed in *"]) result.stdout.fnmatch_lines(["* 1 failed in *"])
else: else:

View File

@ -4,9 +4,7 @@ import py
import pytest import pytest
from _pytest.config import PytestPluginManager from _pytest.config import PytestPluginManager
from _pytest.main import EXIT_NOTESTSCOLLECTED from _pytest.main import ExitCode
from _pytest.main import EXIT_OK
from _pytest.main import EXIT_USAGEERROR
def ConftestWithSetinitial(path): def ConftestWithSetinitial(path):
@ -223,11 +221,11 @@ def test_conftest_symlink(testdir):
"PASSED", "PASSED",
] ]
) )
assert result.ret == EXIT_OK assert result.ret == ExitCode.OK
# Should not cause "ValueError: Plugin already registered" (#4174). # Should not cause "ValueError: Plugin already registered" (#4174).
result = testdir.runpytest("-vs", "symlink") result = testdir.runpytest("-vs", "symlink")
assert result.ret == EXIT_OK assert result.ret == ExitCode.OK
realtests.ensure("__init__.py") realtests.ensure("__init__.py")
result = testdir.runpytest("-vs", "symlinktests/test_foo.py::test1") result = testdir.runpytest("-vs", "symlinktests/test_foo.py::test1")
@ -238,7 +236,7 @@ def test_conftest_symlink(testdir):
"PASSED", "PASSED",
] ]
) )
assert result.ret == EXIT_OK assert result.ret == ExitCode.OK
@pytest.mark.skipif( @pytest.mark.skipif(
@ -274,16 +272,16 @@ def test_conftest_symlink_files(testdir):
build.chdir() build.chdir()
result = testdir.runpytest("-vs", "app/test_foo.py") result = testdir.runpytest("-vs", "app/test_foo.py")
result.stdout.fnmatch_lines(["*conftest_loaded*", "PASSED"]) result.stdout.fnmatch_lines(["*conftest_loaded*", "PASSED"])
assert result.ret == EXIT_OK assert result.ret == ExitCode.OK
def test_no_conftest(testdir): def test_no_conftest(testdir):
testdir.makeconftest("assert 0") testdir.makeconftest("assert 0")
result = testdir.runpytest("--noconftest") result = testdir.runpytest("--noconftest")
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
result = testdir.runpytest() result = testdir.runpytest()
assert result.ret == EXIT_USAGEERROR assert result.ret == ExitCode.USAGE_ERROR
def test_conftest_existing_resultlog(testdir): def test_conftest_existing_resultlog(testdir):

View File

@ -1,5 +1,5 @@
import pytest import pytest
from _pytest.main import EXIT_NOTESTSCOLLECTED from _pytest.main import ExitCode
def test_version(testdir, pytestconfig): def test_version(testdir, pytestconfig):
@ -49,7 +49,7 @@ def test_hookvalidation_optional(testdir):
""" """
) )
result = testdir.runpytest() result = testdir.runpytest()
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
def test_traceconfig(testdir): def test_traceconfig(testdir):
@ -59,7 +59,7 @@ def test_traceconfig(testdir):
def test_debug(testdir, monkeypatch): def test_debug(testdir, monkeypatch):
result = testdir.runpytest_subprocess("--debug") result = testdir.runpytest_subprocess("--debug")
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
p = testdir.tmpdir.join("pytestdebug.log") p = testdir.tmpdir.join("pytestdebug.log")
assert "pytest_sessionstart" in p.read() assert "pytest_sessionstart" in p.read()
@ -67,7 +67,7 @@ def test_debug(testdir, monkeypatch):
def test_PYTEST_DEBUG(testdir, monkeypatch): def test_PYTEST_DEBUG(testdir, monkeypatch):
monkeypatch.setenv("PYTEST_DEBUG", "1") monkeypatch.setenv("PYTEST_DEBUG", "1")
result = testdir.runpytest_subprocess() result = testdir.runpytest_subprocess()
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
result.stderr.fnmatch_lines( result.stderr.fnmatch_lines(
["*pytest_plugin_registered*", "*manager*PluginManager*"] ["*pytest_plugin_registered*", "*manager*PluginManager*"]
) )

View File

@ -3,7 +3,7 @@ import sys
from unittest import mock from unittest import mock
import pytest import pytest
from _pytest.main import EXIT_INTERRUPTED from _pytest.main import ExitCode
from _pytest.mark import EMPTY_PARAMETERSET_OPTION from _pytest.mark import EMPTY_PARAMETERSET_OPTION
from _pytest.mark import MarkGenerator as Mark from _pytest.mark import MarkGenerator as Mark
from _pytest.nodes import Collector from _pytest.nodes import Collector
@ -903,7 +903,7 @@ def test_parameterset_for_fail_at_collect(testdir):
"*= 1 error in *", "*= 1 error in *",
] ]
) )
assert result.ret == EXIT_INTERRUPTED assert result.ret == ExitCode.INTERRUPTED
def test_parameterset_for_parametrize_bad_markname(testdir): def test_parameterset_for_parametrize_bad_markname(testdir):

View File

@ -5,7 +5,7 @@ import types
import pytest import pytest
from _pytest.config import PytestPluginManager from _pytest.config import PytestPluginManager
from _pytest.config.exceptions import UsageError from _pytest.config.exceptions import UsageError
from _pytest.main import EXIT_NOTESTSCOLLECTED from _pytest.main import ExitCode
from _pytest.main import Session from _pytest.main import Session
@ -227,7 +227,7 @@ class TestPytestPluginManager:
p.copy(p.dirpath("skipping2.py")) p.copy(p.dirpath("skipping2.py"))
monkeypatch.setenv("PYTEST_PLUGINS", "skipping2") monkeypatch.setenv("PYTEST_PLUGINS", "skipping2")
result = testdir.runpytest("-rw", "-p", "skipping1", syspathinsert=True) result = testdir.runpytest("-rw", "-p", "skipping1", syspathinsert=True)
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
result.stdout.fnmatch_lines( result.stdout.fnmatch_lines(
["*skipped plugin*skipping1*hello*", "*skipped plugin*skipping2*hello*"] ["*skipped plugin*skipping1*hello*", "*skipped plugin*skipping2*hello*"]
) )

View File

@ -8,9 +8,7 @@ import py.path
import _pytest.pytester as pytester import _pytest.pytester as pytester
import pytest import pytest
from _pytest.config import PytestPluginManager from _pytest.config import PytestPluginManager
from _pytest.main import EXIT_NOTESTSCOLLECTED from _pytest.main import ExitCode
from _pytest.main import EXIT_OK
from _pytest.main import EXIT_TESTSFAILED
from _pytest.pytester import CwdSnapshot from _pytest.pytester import CwdSnapshot
from _pytest.pytester import HookRecorder from _pytest.pytester import HookRecorder
from _pytest.pytester import LineMatcher from _pytest.pytester import LineMatcher
@ -206,11 +204,11 @@ class TestInlineRunModulesCleanup:
def test_inline_run_test_module_not_cleaned_up(self, testdir): def test_inline_run_test_module_not_cleaned_up(self, testdir):
test_mod = testdir.makepyfile("def test_foo(): assert True") test_mod = testdir.makepyfile("def test_foo(): assert True")
result = testdir.inline_run(str(test_mod)) result = testdir.inline_run(str(test_mod))
assert result.ret == EXIT_OK assert result.ret == ExitCode.OK
# rewrite module, now test should fail if module was re-imported # rewrite module, now test should fail if module was re-imported
test_mod.write("def test_foo(): assert False") test_mod.write("def test_foo(): assert False")
result2 = testdir.inline_run(str(test_mod)) result2 = testdir.inline_run(str(test_mod))
assert result2.ret == EXIT_TESTSFAILED assert result2.ret == ExitCode.TESTS_FAILED
def spy_factory(self): def spy_factory(self):
class SysModulesSnapshotSpy: class SysModulesSnapshotSpy:
@ -411,12 +409,12 @@ def test_testdir_subprocess(testdir):
def test_unicode_args(testdir): def test_unicode_args(testdir):
result = testdir.runpytest("-k", "💩") result = testdir.runpytest("-k", "💩")
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
def test_testdir_run_no_timeout(testdir): def test_testdir_run_no_timeout(testdir):
testfile = testdir.makepyfile("def test_no_timeout(): pass") testfile = testdir.makepyfile("def test_no_timeout(): pass")
assert testdir.runpytest_subprocess(testfile).ret == EXIT_OK assert testdir.runpytest_subprocess(testfile).ret == ExitCode.OK
def test_testdir_run_with_timeout(testdir): def test_testdir_run_with_timeout(testdir):
@ -429,7 +427,7 @@ def test_testdir_run_with_timeout(testdir):
end = time.time() end = time.time()
duration = end - start duration = end - start
assert result.ret == EXIT_OK assert result.ret == ExitCode.OK
assert duration < timeout assert duration < timeout

View File

@ -653,7 +653,7 @@ def test_pytest_fail_notrace_non_ascii(testdir):
def test_pytest_no_tests_collected_exit_status(testdir): def test_pytest_no_tests_collected_exit_status(testdir):
result = testdir.runpytest() result = testdir.runpytest()
result.stdout.fnmatch_lines(["*collected 0 items*"]) result.stdout.fnmatch_lines(["*collected 0 items*"])
assert result.ret == main.EXIT_NOTESTSCOLLECTED assert result.ret == main.ExitCode.NO_TESTS_COLLECTED
testdir.makepyfile( testdir.makepyfile(
test_foo=""" test_foo="""
@ -664,12 +664,12 @@ def test_pytest_no_tests_collected_exit_status(testdir):
result = testdir.runpytest() result = testdir.runpytest()
result.stdout.fnmatch_lines(["*collected 1 item*"]) result.stdout.fnmatch_lines(["*collected 1 item*"])
result.stdout.fnmatch_lines(["*1 passed*"]) result.stdout.fnmatch_lines(["*1 passed*"])
assert result.ret == main.EXIT_OK assert result.ret == main.ExitCode.OK
result = testdir.runpytest("-k nonmatch") result = testdir.runpytest("-k nonmatch")
result.stdout.fnmatch_lines(["*collected 1 item*"]) result.stdout.fnmatch_lines(["*collected 1 item*"])
result.stdout.fnmatch_lines(["*1 deselected*"]) result.stdout.fnmatch_lines(["*1 deselected*"])
assert result.ret == main.EXIT_NOTESTSCOLLECTED assert result.ret == main.ExitCode.NO_TESTS_COLLECTED
def test_exception_printing_skip(): def test_exception_printing_skip():

View File

@ -1,5 +1,5 @@
import pytest import pytest
from _pytest.main import EXIT_NOTESTSCOLLECTED from _pytest.main import ExitCode
class SessionTests: class SessionTests:
@ -330,7 +330,7 @@ def test_sessionfinish_with_start(testdir):
""" """
) )
res = testdir.runpytest("--collect-only") res = testdir.runpytest("--collect-only")
assert res.ret == EXIT_NOTESTSCOLLECTED assert res.ret == ExitCode.NO_TESTS_COLLECTED
@pytest.mark.parametrize("path", ["root", "{relative}/root", "{environment}/root"]) @pytest.mark.parametrize("path", ["root", "{relative}/root", "{environment}/root"])

View File

@ -10,7 +10,7 @@ import pluggy
import py import py
import pytest import pytest
from _pytest.main import EXIT_NOTESTSCOLLECTED from _pytest.main import ExitCode
from _pytest.reports import BaseReport from _pytest.reports import BaseReport
from _pytest.terminal import _folded_skips from _pytest.terminal import _folded_skips
from _pytest.terminal import _get_line_with_reprcrash_message from _pytest.terminal import _get_line_with_reprcrash_message
@ -937,7 +937,7 @@ def test_tbstyle_short(testdir):
def test_traceconfig(testdir, monkeypatch): def test_traceconfig(testdir, monkeypatch):
result = testdir.runpytest("--traceconfig") result = testdir.runpytest("--traceconfig")
result.stdout.fnmatch_lines(["*active plugins*"]) result.stdout.fnmatch_lines(["*active plugins*"])
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
class TestGenericReporting: class TestGenericReporting:

View File

@ -1,7 +1,7 @@
import gc import gc
import pytest import pytest
from _pytest.main import EXIT_NOTESTSCOLLECTED from _pytest.main import ExitCode
def test_simple_unittest(testdir): def test_simple_unittest(testdir):
@ -55,7 +55,7 @@ def test_isclasscheck_issue53(testdir):
""" """
) )
result = testdir.runpytest(testpath) result = testdir.runpytest(testpath)
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
def test_setup(testdir): def test_setup(testdir):
@ -704,7 +704,7 @@ def test_unorderable_types(testdir):
) )
result = testdir.runpytest() result = testdir.runpytest()
assert "TypeError" not in result.stdout.str() assert "TypeError" not in result.stdout.str()
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == ExitCode.NO_TESTS_COLLECTED
def test_unittest_typerror_traceback(testdir): def test_unittest_typerror_traceback(testdir):