diff --git a/src/_pytest/main.py b/src/_pytest/main.py index 052b49b5f4e..3aa36c80f14 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -1,6 +1,6 @@ """ core implementation of testing process: init, session, runtest loop. """ -import fnmatch import enum +import fnmatch import functools import os import pkgutil @@ -202,7 +202,7 @@ def wrap_session(config, doit): initstate = 2 session.exitstatus = doit(config, session) or 0 except UsageError: - session.exitstatus = EXIT_USAGEERROR + session.exitstatus = ExitCode.USAGE_ERROR raise except Failed: session.exitstatus = ExitCode.TESTS_FAILED diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 73224420914..60cc21c4a01 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -409,10 +409,10 @@ def test_a(): def test_report_all_failed_collections_initargs(self, testdir): testdir.makeconftest( """ - from _pytest.main import EXIT_USAGEERROR + from _pytest.main import ExitCode def pytest_sessionfinish(exitstatus): - assert exitstatus == EXIT_USAGEERROR + assert exitstatus == ExitCode.USAGE_ERROR print("pytest_sessionfinish_called") """ ) @@ -420,7 +420,7 @@ def pytest_sessionfinish(exitstatus): 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.stdout.fnmatch_lines(["pytest_sessionfinish_called"]) - assert result.ret == EXIT_USAGEERROR + assert result.ret == ExitCode.USAGE_ERROR @pytest.mark.usefixtures("recwarn") def test_namespace_import_doesnt_confuse_import_hook(self, testdir): diff --git a/testing/test_cacheprovider.py b/testing/test_cacheprovider.py index a2e701740a0..cbba27e5f5d 100644 --- a/testing/test_cacheprovider.py +++ b/testing/test_cacheprovider.py @@ -6,7 +6,7 @@ import py import pytest -from _pytest.main import EXIT_NOTESTSCOLLECTED +from _pytest.main import ExitCode pytest_plugins = ("pytester",) @@ -757,7 +757,7 @@ def test_2(): "* 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): testdir.makepyfile( diff --git a/testing/test_collection.py b/testing/test_collection.py index 28202473108..864125c40af 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -383,7 +383,7 @@ def pytest_configure(config): testdir.makepyfile(test_world="def test_hello(): pass") testdir.makepyfile(test_welt="def test_hallo(): pass") result = testdir.runpytest() - assert result.ret == EXIT_NOTESTSCOLLECTED + assert result.ret == ExitCode.NO_TESTS_COLLECTED result.stdout.fnmatch_lines(["*collected 0 items*"]) result = testdir.runpytest("--XX") assert result.ret == 0 @@ -1171,7 +1171,7 @@ def test_collectignore_via_conftest(testdir, monkeypatch): ignore_me.ensure("conftest.py").write("assert 0, 'should_not_be_called'") 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): @@ -1233,7 +1233,7 @@ def test_collect_sub_with_symlinks(use_pkg, testdir): def test_collector_respects_tbstyle(testdir): p1 = testdir.makepyfile("assert 0") result = testdir.runpytest(p1, "--tb=native") - assert result.ret == EXIT_INTERRUPTED + assert result.ret == ExitCode.INTERRUPTED result.stdout.fnmatch_lines( [ "*_ ERROR collecting test_collector_respects_tbstyle.py _*", diff --git a/testing/test_config.py b/testing/test_config.py index 8c3811b76b3..b9fc388d236 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -11,9 +11,6 @@ from _pytest.config.findpaths import get_common_ancestor from _pytest.config.findpaths import getcfg 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: @@ -1175,13 +1172,13 @@ def pytest_addoption(parser): ) # Does not display full/default help. 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.stderr.fnmatch_lines( ["*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): @@ -1189,11 +1186,11 @@ def test_config_does_not_load_blocked_plugin_from_args(testdir): p = testdir.makepyfile("def test(capfd): pass") result = testdir.runpytest(str(p), "-pno:capture") 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.stderr.fnmatch_lines(["*: error: unrecognized arguments: -s"]) - assert result.ret == EXIT_USAGEERROR + assert result.ret == ExitCode.USAGE_ERROR @pytest.mark.parametrize( @@ -1219,7 +1216,7 @@ def test_config_blocked_default_plugins(testdir, plugin): result = testdir.runpytest(str(p), "-pno:%s" % plugin) if plugin == "python": - assert result.ret == EXIT_USAGEERROR + assert result.ret == ExitCode.USAGE_ERROR result.stderr.fnmatch_lines( [ "ERROR: not found: */test_config_blocked_default_plugins.py", @@ -1228,13 +1225,13 @@ def test_config_blocked_default_plugins(testdir, plugin): ) return - assert result.ret == EXIT_OK + assert result.ret == ExitCode.OK if plugin != "terminal": result.stdout.fnmatch_lines(["* 1 passed in *"]) p = testdir.makepyfile("def test(): assert 0") result = testdir.runpytest(str(p), "-pno:%s" % plugin) - assert result.ret == EXIT_TESTSFAILED + assert result.ret == ExitCode.TESTS_FAILED if plugin != "terminal": result.stdout.fnmatch_lines(["* 1 failed in *"]) else: diff --git a/testing/test_conftest.py b/testing/test_conftest.py index 2fdd8f13f47..447416f1076 100644 --- a/testing/test_conftest.py +++ b/testing/test_conftest.py @@ -272,7 +272,7 @@ def fixture(): build.chdir() result = testdir.runpytest("-vs", "app/test_foo.py") result.stdout.fnmatch_lines(["*conftest_loaded*", "PASSED"]) - assert result.ret == EXIT_OK + assert result.ret == ExitCode.OK def test_no_conftest(testdir): diff --git a/testing/test_mark.py b/testing/test_mark.py index 8d97f8b4ef5..c22e9dbb5de 100644 --- a/testing/test_mark.py +++ b/testing/test_mark.py @@ -3,7 +3,7 @@ from unittest import mock import pytest -from _pytest.main import EXIT_INTERRUPTED +from _pytest.main import ExitCode from _pytest.mark import EMPTY_PARAMETERSET_OPTION from _pytest.mark import MarkGenerator as Mark from _pytest.nodes import Collector @@ -903,7 +903,7 @@ def test(): "*= 1 error in *", ] ) - assert result.ret == EXIT_INTERRUPTED + assert result.ret == ExitCode.INTERRUPTED def test_parameterset_for_parametrize_bad_markname(testdir):