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

@@ -584,7 +584,13 @@ class Session(nodes.FSCollector):
# Module itself, so just use that. If this special case isn't taken, then all
# the files in the package will be yielded.
if argpath.basename == "__init__.py":
yield next(m[0].collect())
try:
yield next(m[0].collect())
except StopIteration:
# The package collects nothing with only an __init__.py
# file in it, which gets ignored by the default
# "python_files" option.
pass
return
yield from m