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

Function compute_module_name

src/_pytest/pathlib.py:917–934  ·  view source on GitHub ↗

Compute a module name based on a path and a root anchor.

(root: Path, module_path: Path)

Source from the content-addressed store, hash-verified

915
916
917def compute_module_name(root: Path, module_path: Path) -> str | None:
918 """Compute a module name based on a path and a root anchor."""
919 try:
920 path_without_suffix = module_path.with_suffix("")
921 except ValueError:
922 # Empty paths (such as Path.cwd()) might break meta_path hooks (like our own assertion rewriter).
923 return None
924
925 try:
926 relative = path_without_suffix.relative_to(root)
927 except ValueError: # pragma: no cover
928 return None
929 names = list(relative.parts)
930 if not names:
931 return None
932 if names[-1] == "__init__":
933 names.pop()
934 return ".".join(names)
935
936
937class CouldNotResolvePathError(Exception):

Callers 2

test_compute_module_nameFunction · 0.90

Calls 2

popMethod · 0.80
joinMethod · 0.80

Tested by 1

test_compute_module_nameFunction · 0.72