Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5ac4eff

Browse files
committed
Fix __init__.py as argument also including other package files
1 parent 320e41b commit 5ac4eff

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/_pytest/main.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,15 @@ def _collect(self, arg):
542542
col = root._collectfile(argpath)
543543
if col:
544544
self._node_cache[argpath] = col
545-
for y in self.matchnodes(col, names):
545+
m = self.matchnodes(col, names)
546+
# If __init__.py was the only file requested, then the matched node will be
547+
# the corresponding Package, and the first yielded item will be the __init__
548+
# Module itself, so just use that. If this special case isn't taken, then all
549+
# the files in the package will be yielded.
550+
if argpath.basename == "__init__.py":
551+
yield next(m[0].collect())
552+
return
553+
for y in m:
546554
yield y
547555

548556
def _collectfile(self, path):

0 commit comments

Comments
 (0)