Skip to content

main: change pkg_roots to work with Paths instead of string paths #11078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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