Tests: Check for ModuleNotFoundError on Python 3.6+
Those tests originally checked for ImportError. Since Python 3.6 ModuleNotFoundError is raised in this context instead, the tests didn't work as they are text based (so exception inheritance does not save the day). Fixes https://github.com/pytest-dev/pytest/issues/2132
This commit is contained in:
parent
da40bcf97f
commit
1680eeb3a3
|
@ -4,6 +4,10 @@ import _pytest._code
|
|||
from _pytest.doctest import DoctestItem, DoctestModule, DoctestTextfile
|
||||
import pytest
|
||||
|
||||
PY36 = sys.version_info[:2] >= (3, 6)
|
||||
MODULE_NOT_FOUND_ERROR = 'ModuleNotFoundError' if PY36 else 'ImportError'
|
||||
|
||||
|
||||
class TestDoctests:
|
||||
|
||||
def test_collect_testtextfile(self, testdir):
|
||||
|
@ -211,8 +215,8 @@ class TestDoctests:
|
|||
# doctest is never executed because of error during hello.py collection
|
||||
result.stdout.fnmatch_lines([
|
||||
"*>>> import asdals*",
|
||||
"*UNEXPECTED*ImportError*",
|
||||
"ImportError: No module named *asdal*",
|
||||
"*UNEXPECTED*{e}*".format(e=MODULE_NOT_FOUND_ERROR),
|
||||
"{e}: No module named *asdal*".format(e=MODULE_NOT_FOUND_ERROR),
|
||||
])
|
||||
|
||||
def test_doctest_unex_importerror_with_module(self, testdir):
|
||||
|
@ -227,7 +231,7 @@ class TestDoctests:
|
|||
# doctest is never executed because of error during hello.py collection
|
||||
result.stdout.fnmatch_lines([
|
||||
"*ERROR collecting hello.py*",
|
||||
"*ImportError: No module named *asdals*",
|
||||
"*{e}: No module named *asdals*".format(e=MODULE_NOT_FOUND_ERROR),
|
||||
"*Interrupted: 1 errors during collection*",
|
||||
])
|
||||
|
||||
|
|
Loading…
Reference in New Issue