MCPcopy Create free account
hub / github.com/pytest-dev/pytest / resolve_package_path

Function resolve_package_path

src/_pytest/pathlib.py:613–627  ·  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 can not be determined.

(path: Path)

Source from the content-addressed store, hash-verified

611
612
613def resolve_package_path(path: Path) -> Optional[Path]:
614 """Return the Python package path by looking for the last
615 directory upwards which still contains an __init__.py.
616
617 Returns None if it can not be determined.
618 """
619 result = None
620 for parent in itertools.chain((path,), path.parents):
621 if parent.is_dir():
622 if not parent.joinpath("__init__.py").is_file():
623 break
624 if not parent.name.isidentifier():
625 break
626 result = parent
627 return result
628
629
630def visit(

Callers 4

_importconftestMethod · 0.90
import_pathFunction · 0.85

Calls

no outgoing calls

Tested by 2