Skip to content

Commit

Permalink
Fix __init__.py as argument also including other package files
Browse files Browse the repository at this point in the history
  • Loading branch information
kchmck committed Nov 1, 2018
1 parent 320e41b commit 5ac4eff
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/_pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,15 @@ def _collect(self, arg):
col = root._collectfile(argpath)
if col:
self._node_cache[argpath] = col
for y in self.matchnodes(col, names):
m = self.matchnodes(col, names)
# If __init__.py was the only file requested, then the matched node will be
# the corresponding Package, and the first yielded item will be the __init__
# 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())
return
for y in m:
yield y

def _collectfile(self, path):
Expand Down

0 comments on commit 5ac4eff

Please sign in to comment.