Skip to content

Commit

Permalink
main: slight refactor to collection argument parents logic
Browse files Browse the repository at this point in the history
No logical change, preparation for the next commit.
  • Loading branch information
bluetech committed Mar 1, 2024
1 parent 82cfa21 commit c14ff86
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/_pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,13 +851,14 @@ def collect(self) -> Iterator[Union[nodes.Item, nodes.Collector]]:
if argpath.is_dir():
assert not names, f"invalid arg {(argpath, names)!r}"

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

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

0 comments on commit c14ff86

Please sign in to comment.