Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/_pytest/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ def resolve_package_path(path: Path) -> Optional[Path]:
result = None
for parent in itertools.chain((path,), path.parents):
if parent.is_dir():
if not parent.joinpath("__init__.py").is_file():
if not (parent / "__init__.py").is_file():
break
if not parent.name.isidentifier():
break
Expand Down
8 changes: 4 additions & 4 deletions testing/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,18 +345,18 @@ def test_resolve_package_path(tmp_path: Path) -> None:
(pkg / "subdir").mkdir()
(pkg / "subdir/__init__.py").touch()
assert resolve_package_path(pkg) == pkg
assert resolve_package_path(pkg.joinpath("subdir", "__init__.py")) == pkg
assert resolve_package_path(pkg / "subdir/__init__.py") == pkg


def test_package_unimportable(tmp_path: Path) -> None:
pkg = tmp_path / "pkg1-1"
pkg.mkdir()
pkg.joinpath("__init__.py").touch()
subdir = pkg.joinpath("subdir")
subdir = pkg / "subdir"
subdir.mkdir()
pkg.joinpath("subdir/__init__.py").touch()
(pkg / "subdir/__init__.py").touch()
assert resolve_package_path(subdir) == subdir
xyz = subdir.joinpath("xyz.py")
xyz = subdir / "xyz.py"
xyz.touch()
assert resolve_package_path(xyz) == subdir
assert not resolve_package_path(pkg)
Expand Down