Merge pull request #2136 from hroncok/i2132
Tests: Check for ModuleNotFoundError on Python 3.6+
This commit is contained in:
		
						commit
						091148f843
					
				|  | @ -33,6 +33,9 @@ matrix: | ||||||
|     # see #1989 |     # see #1989 | ||||||
|     - env: TESTENV=py27-trial |     - env: TESTENV=py27-trial | ||||||
|     - env: TESTENV=py35-trial |     - env: TESTENV=py35-trial | ||||||
|  |   include: | ||||||
|  |     - env: TESTENV=py36 | ||||||
|  |       python: '3.6-dev' | ||||||
| 
 | 
 | ||||||
| script: tox --recreate -e $TESTENV | script: tox --recreate -e $TESTENV | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -27,6 +27,9 @@ _PY2 = not _PY3 | ||||||
| NoneType = type(None) | NoneType = type(None) | ||||||
| NOTSET = object() | NOTSET = object() | ||||||
| 
 | 
 | ||||||
|  | PY36 = sys.version_info[:2] >= (3, 6) | ||||||
|  | MODULE_NOT_FOUND_ERROR = 'ModuleNotFoundError' if PY36 else 'ImportError' | ||||||
|  | 
 | ||||||
| if hasattr(inspect, 'signature'): | if hasattr(inspect, 'signature'): | ||||||
|     def _format_args(func): |     def _format_args(func): | ||||||
|         return str(inspect.signature(func)) |         return str(inspect.signature(func)) | ||||||
|  |  | ||||||
|  | @ -1,9 +1,11 @@ | ||||||
| # encoding: utf-8 | # encoding: utf-8 | ||||||
| import sys | import sys | ||||||
| import _pytest._code | import _pytest._code | ||||||
|  | from _pytest.compat import MODULE_NOT_FOUND_ERROR | ||||||
| from _pytest.doctest import DoctestItem, DoctestModule, DoctestTextfile | from _pytest.doctest import DoctestItem, DoctestModule, DoctestTextfile | ||||||
| import pytest | import pytest | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| class TestDoctests: | class TestDoctests: | ||||||
| 
 | 
 | ||||||
|     def test_collect_testtextfile(self, testdir): |     def test_collect_testtextfile(self, testdir): | ||||||
|  | @ -211,8 +213,8 @@ class TestDoctests: | ||||||
|         # doctest is never executed because of error during hello.py collection |         # doctest is never executed because of error during hello.py collection | ||||||
|         result.stdout.fnmatch_lines([ |         result.stdout.fnmatch_lines([ | ||||||
|             "*>>> import asdals*", |             "*>>> import asdals*", | ||||||
|             "*UNEXPECTED*ImportError*", |             "*UNEXPECTED*{e}*".format(e=MODULE_NOT_FOUND_ERROR), | ||||||
|             "ImportError: No module named *asdal*", |             "{e}: No module named *asdal*".format(e=MODULE_NOT_FOUND_ERROR), | ||||||
|         ]) |         ]) | ||||||
| 
 | 
 | ||||||
|     def test_doctest_unex_importerror_with_module(self, testdir): |     def test_doctest_unex_importerror_with_module(self, testdir): | ||||||
|  | @ -227,7 +229,7 @@ class TestDoctests: | ||||||
|         # doctest is never executed because of error during hello.py collection |         # doctest is never executed because of error during hello.py collection | ||||||
|         result.stdout.fnmatch_lines([ |         result.stdout.fnmatch_lines([ | ||||||
|             "*ERROR collecting hello.py*", |             "*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*", |             "*Interrupted: 1 errors during collection*", | ||||||
|         ]) |         ]) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue