Skip to content

Tests: Check for ModuleNotFoundError on Python 3.6+ #2136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ matrix:
allow_failures:
# py35-trial failing on Linux: #1989
- env: TESTENV=py35-trial
include:
- env: TESTENV=py36
python: '3.6-dev'

script: tox --recreate -e $TESTENV

Expand Down
3 changes: 3 additions & 0 deletions _pytest/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
NoneType = type(None)
NOTSET = object()

PY36 = sys.version_info[:2] >= (3, 6)
MODULE_NOT_FOUND_ERROR = 'ModuleNotFoundError' if PY36 else 'ImportError'

if hasattr(inspect, 'signature'):
def _format_args(func):
return str(inspect.signature(func))
Expand Down
8 changes: 5 additions & 3 deletions testing/test_doctest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# encoding: utf-8
import sys
import _pytest._code
from _pytest.compat import MODULE_NOT_FOUND_ERROR
from _pytest.doctest import DoctestItem, DoctestModule, DoctestTextfile
import pytest


class TestDoctests:

def test_collect_testtextfile(self, testdir):
Expand Down Expand Up @@ -211,8 +213,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 +229,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
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ envlist=
py33
py34
py35
py36
pypy
{py27,py35}-{pexpect,xdist,trial}
py27-nobyte
Expand Down