Skip to content

Commit

Permalink
Merge pull request #7833 from asottile/py36_ModuleNotFoundError
Browse files Browse the repository at this point in the history
py36+: remove _pytest.compat.MODULE_NOT_FOUND_ERROR
  • Loading branch information
asottile committed Oct 3, 2020
2 parents 7836c2c + 1f57fb0 commit a6ef0f8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 18 deletions.
5 changes: 0 additions & 5 deletions src/_pytest/compat.py
Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions testing/acceptance_test.py
Expand Up @@ -210,17 +210,14 @@ 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),
"conftest.py:3: in <module>",
" 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):
Expand Down
7 changes: 2 additions & 5 deletions testing/test_collection.py
Expand Up @@ -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 *",
]
)
Expand Down
7 changes: 3 additions & 4 deletions testing/test_doctest.py
Expand Up @@ -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
Expand Down Expand Up @@ -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*",
]
)

Expand All @@ -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*",
]
)
Expand Down

0 comments on commit a6ef0f8

Please sign in to comment.