Skip to content

Commit f20e32c

Browse files
committed
main: slight refactor to collection argument parents logic
No logical change, preparation for the next commit.
1 parent 1612d4e commit f20e32c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/_pytest/main.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -851,13 +851,14 @@ def collect(self) -> Iterator[Union[nodes.Item, nodes.Collector]]:
851851
if argpath.is_dir():
852852
assert not names, f"invalid arg {(argpath, names)!r}"
853853

854-
# Match the argpath from the root, e.g.
854+
paths = [argpath]
855+
# Add relevant parents of the path, from the root, e.g.
855856
# /a/b/c.py -> [/, /a, /a/b, /a/b/c.py]
856-
paths = [*reversed(argpath.parents), argpath]
857-
# Paths outside of the confcutdir should not be considered, unless
858-
# it's the argpath itself.
859-
while len(paths) > 1 and not pm._is_in_confcutdir(paths[0]):
860-
paths = paths[1:]
857+
# Paths outside of the confcutdir should not be considered.
858+
for path in argpath.parents:
859+
if not pm._is_in_confcutdir(path):
860+
break
861+
paths.insert(0, path)
861862

862863
# Start going over the parts from the root, collecting each level
863864
# and discarding all nodes which don't match the level's part.

0 commit comments

Comments
 (0)