diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py index 33221aac2d0..c28e904cbe8 100644 --- a/src/_pytest/compat.py +++ b/src/_pytest/compat.py @@ -46,11 +46,6 @@ class NotSetType(enum.Enum): NOTSET = NotSetType.token # type: Final # noqa: E305 # fmt: on -MODULE_NOT_FOUND_ERROR = ( - "ModuleNotFoundError" if sys.version_info[:2] >= (3, 6) else "ImportError" -) - - if sys.version_info >= (3, 8): from importlib import metadata as importlib_metadata else: diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 039d8dad969..b3598901a6b 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -210,9 +210,6 @@ def foo(): """ ) result = testdir.runpytest() - exc_name = ( - "ModuleNotFoundError" if sys.version_info >= (3, 6) else "ImportError" - ) assert result.stdout.lines == [] assert result.stderr.lines == [ "ImportError while loading conftest '{}'.".format(conftest), @@ -220,7 +217,7 @@ def foo(): " foo()", "conftest.py:2: in foo", " import qwerty", - "E {}: No module named 'qwerty'".format(exc_name), + "E ModuleNotFoundError: No module named 'qwerty'", ] def test_early_skip(self, testdir): diff --git a/testing/test_collection.py b/testing/test_collection.py index 3e1b816b79e..3cb342a93d5 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -1383,13 +1383,10 @@ def test_modules_not_importable_as_side_effect(self, testdir): """ self.setup_conftest_and_foo(testdir) result = testdir.runpytest("-v", "--import-mode=importlib") - exc_name = ( - "ModuleNotFoundError" if sys.version_info[:2] > (3, 5) else "ImportError" - ) result.stdout.fnmatch_lines( [ - "*{}: No module named 'foo'".format(exc_name), - "tests?test_foo.py:2: {}".format(exc_name), + "*ModuleNotFoundError: No module named 'foo'", + "tests?test_foo.py:2: ModuleNotFoundError", "* 1 failed in *", ] ) diff --git a/testing/test_doctest.py b/testing/test_doctest.py index 0b32ad32203..13b85979782 100644 --- a/testing/test_doctest.py +++ b/testing/test_doctest.py @@ -4,7 +4,6 @@ from typing import Optional import pytest -from _pytest.compat import MODULE_NOT_FOUND_ERROR from _pytest.doctest import _get_checker from _pytest.doctest import _is_mocked from _pytest.doctest import _is_setup_py @@ -399,8 +398,8 @@ def test_doctest_unex_importerror_only_txt(self, testdir): result.stdout.fnmatch_lines( [ "*>>> import asdals*", - "*UNEXPECTED*{e}*".format(e=MODULE_NOT_FOUND_ERROR), - "{e}: No module named *asdal*".format(e=MODULE_NOT_FOUND_ERROR), + "*UNEXPECTED*ModuleNotFoundError*", + "ModuleNotFoundError: No module named *asdal*", ] ) @@ -423,7 +422,7 @@ def test_doctest_unex_importerror_with_module(self, testdir): result.stdout.fnmatch_lines( [ "*ERROR collecting hello.py*", - "*{e}: No module named *asdals*".format(e=MODULE_NOT_FOUND_ERROR), + "*ModuleNotFoundError: No module named *asdals*", "*Interrupted: 1 error during collection*", ] )