Fix RuntimeError when trying to collect package with "__init__.py" only

Fixes https://github.com/pytest-dev/pytest/issues/4344.
This commit is contained in:
Daniel Hahler
2019-08-05 17:51:51 +02:00
parent 1a66a503b6
commit 198fcd8a6f
3 changed files with 20 additions and 1 deletions

View File

@@ -1203,6 +1203,18 @@ def test_collect_pkg_init_and_file_in_args(testdir):
)
def test_collect_pkg_init_only(testdir):
subdir = testdir.mkdir("sub")
init = subdir.ensure("__init__.py")
init.write("def test_init(): pass")
result = testdir.runpytest(str(init))
result.stdout.fnmatch_lines(["*no tests ran in*"])
result = testdir.runpytest("-v", "-o", "python_files=*.py", str(init))
result.stdout.fnmatch_lines(["sub/__init__.py::test_init PASSED*", "*1 passed in*"])
@pytest.mark.skipif(
not hasattr(py.path.local, "mksymlinkto"),
reason="symlink not available on this platform",