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

Function commonpath

src/_pytest/pathlib.py:998–1007  ·  view source on GitHub ↗

Return the common part shared with the other path, or None if there is no common part. If one path is relative and one is absolute, returns None.

(path1: Path, path2: Path)

Source from the content-addressed store, hash-verified

996
997
998def commonpath(path1: Path, path2: Path) -> Path | None:
999 """Return the common part shared with the other path, or None if there is
1000 no common part.
1001
1002 If one path is relative and one is absolute, returns None.
1003 """
1004 try:
1005 return Path(os.path.commonpath((str(path1), str(path2))))
1006 except ValueError:
1007 return None
1008
1009
1010def bestrelpath(directory: Path, dest: Path) -> str:

Callers 3

get_common_ancestorFunction · 0.90
test_commonpathFunction · 0.90
bestrelpathFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_commonpathFunction · 0.72