Raise CollectError if import test module fails
One of the reasons for failing to import the test module is invalid Python identifiers in the full package path of the test module. fix #1426
This commit is contained in:
@@ -5,14 +5,16 @@ from textwrap import dedent
|
||||
import _pytest._code
|
||||
import py
|
||||
import pytest
|
||||
from _pytest.main import EXIT_NOTESTSCOLLECTED
|
||||
from _pytest.main import (
|
||||
Collector,
|
||||
EXIT_NOTESTSCOLLECTED
|
||||
)
|
||||
|
||||
|
||||
class TestModule:
|
||||
def test_failing_import(self, testdir):
|
||||
modcol = testdir.getmodulecol("import alksdjalskdjalkjals")
|
||||
pytest.raises(ImportError, modcol.collect)
|
||||
pytest.raises(ImportError, modcol.collect)
|
||||
pytest.raises(Collector.CollectError, modcol.collect)
|
||||
|
||||
def test_import_duplicate(self, testdir):
|
||||
a = testdir.mkdir("a")
|
||||
@@ -60,6 +62,16 @@ class TestModule:
|
||||
modcol = testdir.getmodulecol("pytest_plugins='xasdlkj',")
|
||||
pytest.raises(ImportError, lambda: modcol.obj)
|
||||
|
||||
def test_invalid_test_module_name(self, testdir):
|
||||
a = testdir.mkdir('a')
|
||||
a.ensure('test_one.part1.py')
|
||||
result = testdir.runpytest("-rw")
|
||||
result.stdout.fnmatch_lines([
|
||||
"ImportError while importing test module*test_one.part1*",
|
||||
"Make sure your test modules/packages have valid Python names.",
|
||||
])
|
||||
|
||||
|
||||
class TestClass:
|
||||
def test_class_with_init_warning(self, testdir):
|
||||
testdir.makepyfile("""
|
||||
|
||||
Reference in New Issue
Block a user