MCPcopy
hub / github.com/pytest-dev/pytest / resolve_package_path

Function resolve_package_path

src/_pytest/pathlib.py:830–844  ·  view source on GitHub ↗

Return the Python package path by looking for the last directory upwards which still contains an __init__.py. Returns None if it cannot be determined.

(path: Path)

Source from the content-addressed store, hash-verified

828
829
830def resolve_package_path(path: Path) -> Path | None:
831 """Return the Python package path by looking for the last
832 directory upwards which still contains an __init__.py.
833
834 Returns None if it cannot be determined.
835 """
836 result = None
837 for parent in itertools.chain((path,), path.parents):
838 if parent.is_dir():
839 if not (parent / "__init__.py").is_file():
840 break
841 if not parent.name.isidentifier():
842 break
843 result = parent
844 return result
845
846
847def resolve_pkg_root_and_module_name(

Callers 4

_importconftestMethod · 0.90

Calls

no outgoing calls

Tested by 2