Skip to content

Commit

Permalink
Tests: Check for ModuleNotFoundError on Python 3.6+
Browse files Browse the repository at this point in the history
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 pytest-dev#2132
  • Loading branch information
hroncok committed Dec 27, 2016
1 parent da40bcf commit 1680eeb
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions testing/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
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):
Expand Down Expand Up @@ -211,8 +215,8 @@ def test_doctest_unex_importerror_only_txt(self, testdir):
# 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):
Expand All @@ -227,7 +231,7 @@ def test_doctest_unex_importerror_with_module(self, testdir):
# 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*",
])

Expand Down

0 comments on commit 1680eeb

Please sign in to comment.