Skip to content

Commit e1204e1

Browse files
authored
Merge pull request #11078 from bluetech/pkg-roots-path
main: change pkg_roots to work with `Path`s instead of string paths
2 parents b5ff089 + 313b614 commit e1204e1

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/_pytest/main.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,8 @@ def collect(self) -> Iterator[Union[nodes.Item, nodes.Collector]]:
686686
# are not collected more than once.
687687
matchnodes_cache: Dict[Tuple[Type[nodes.Collector], str], CollectReport] = {}
688688

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

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

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

719719
seen_dirs: Set[Path] = set()
720-
for direntry in visit(str(argpath), self._recurse):
720+
for direntry in visit(argpath, self._recurse):
721721
if not direntry.is_file():
722722
continue
723723

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

@@ -750,7 +750,7 @@ def collect(self) -> Iterator[Union[nodes.Item, nodes.Collector]]:
750750
if argpath in node_cache1:
751751
col = node_cache1[argpath]
752752
else:
753-
collect_root = pkg_roots.get(str(argpath.parent), self)
753+
collect_root = pkg_roots.get(argpath.parent, self)
754754
col = collect_root._collectfile(argpath, handle_dupes=False)
755755
if col:
756756
node_cache1[argpath] = col

0 commit comments

Comments
 (0)