Skip to content

Commit

Permalink
Merge pull request #11078 from bluetech/pkg-roots-path
Browse files Browse the repository at this point in the history
main: change pkg_roots to work with `Path`s instead of string paths
  • Loading branch information
bluetech committed Jun 4, 2023
2 parents b5ff089 + 313b614 commit e1204e1
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/_pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,8 @@ def collect(self) -> Iterator[Union[nodes.Item, nodes.Collector]]:
# are not collected more than once.
matchnodes_cache: Dict[Tuple[Type[nodes.Collector], str], CollectReport] = {}

# Dirnames of pkgs with dunder-init files.
pkg_roots: Dict[str, Package] = {}
# Directories of pkgs with dunder-init files.
pkg_roots: Dict[Path, Package] = {}

for argpath, names in self._initial_parts:
self.trace("processing argument", (argpath, names))
Expand All @@ -708,7 +708,7 @@ def collect(self) -> Iterator[Union[nodes.Item, nodes.Collector]]:
col = self._collectfile(pkginit, handle_dupes=False)
if col:
if isinstance(col[0], Package):
pkg_roots[str(parent)] = col[0]
pkg_roots[parent] = col[0]
node_cache1[col[0].path] = [col[0]]

# If it's a directory argument, recurse and look for any Subpackages.
Expand All @@ -717,7 +717,7 @@ def collect(self) -> Iterator[Union[nodes.Item, nodes.Collector]]:
assert not names, f"invalid arg {(argpath, names)!r}"

seen_dirs: Set[Path] = set()
for direntry in visit(str(argpath), self._recurse):
for direntry in visit(argpath, self._recurse):
if not direntry.is_file():
continue

Expand All @@ -732,8 +732,8 @@ def collect(self) -> Iterator[Union[nodes.Item, nodes.Collector]]:
for x in self._collectfile(pkginit):
yield x
if isinstance(x, Package):
pkg_roots[str(dirpath)] = x
if str(dirpath) in pkg_roots:
pkg_roots[dirpath] = x
if dirpath in pkg_roots:
# Do not collect packages here.
continue

Expand All @@ -750,7 +750,7 @@ def collect(self) -> Iterator[Union[nodes.Item, nodes.Collector]]:
if argpath in node_cache1:
col = node_cache1[argpath]
else:
collect_root = pkg_roots.get(str(argpath.parent), self)
collect_root = pkg_roots.get(argpath.parent, self)
col = collect_root._collectfile(argpath, handle_dupes=False)
if col:
node_cache1[argpath] = col
Expand Down

0 comments on commit e1204e1

Please sign in to comment.