From 1680eeb3a3cf13892c5fae59a9d251727370df39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 13 Dec 2016 13:49:44 +0100 Subject: [PATCH 1/3] 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 --- testing/test_doctest.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/testing/test_doctest.py b/testing/test_doctest.py index 4ea2cc58e..196a5670e 100644 --- a/testing/test_doctest.py +++ b/testing/test_doctest.py @@ -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*", ]) From 6b24ce2a9d618bbda2c2f1dd70c8d7f43c474473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 13 Dec 2016 15:16:06 +0100 Subject: [PATCH 2/3] Test Python 3.6 on Travis CI Partial fix for https://github.com/pytest-dev/pytest/issues/2134 --- .travis.yml | 3 +++ tox.ini | 1 + 2 files changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index bbc03d856..c4699ec4b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/tox.ini b/tox.ini index f3494e8be..a5dec3fdc 100644 --- a/tox.ini +++ b/tox.ini @@ -9,6 +9,7 @@ envlist= py33 py34 py35 + py36 pypy {py27,py35}-{pexpect,xdist,trial} py27-nobyte From 515fb099957286b6c692d0fb95b789dbfcae6b0a Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 27 Dec 2016 22:01:22 -0200 Subject: [PATCH 3/3] Move module error compatibility code to _pytest.compat --- _pytest/compat.py | 3 +++ testing/test_doctest.py | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/_pytest/compat.py b/_pytest/compat.py index 51fc3bc5c..8f4d0a8e6 100644 --- a/_pytest/compat.py +++ b/_pytest/compat.py @@ -26,6 +26,9 @@ _PY2 = not _PY3 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)) diff --git a/testing/test_doctest.py b/testing/test_doctest.py index 196a5670e..faf75ef33 100644 --- a/testing/test_doctest.py +++ b/testing/test_doctest.py @@ -1,12 +1,10 @@ # 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 -PY36 = sys.version_info[:2] >= (3, 6) -MODULE_NOT_FOUND_ERROR = 'ModuleNotFoundError' if PY36 else 'ImportError' - class TestDoctests: