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

Function commonpath

src/_pytest/pathlib.py:668–677  ·  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

666
667
668def commonpath(path1: Path, path2: Path) -> Optional[Path]:
669 """Return the common part shared with the other path, or None if there is
670 no common part.
671
672 If one path is relative and one is absolute, returns None.
673 """
674 try:
675 return Path(os.path.commonpath((str(path1), str(path2))))
676 except ValueError:
677 return None
678
679
680def bestrelpath(directory: Path, dest: Path) -> str:

Callers 4

get_common_ancestorFunction · 0.90
test_commonpathFunction · 0.90
bestrelpathFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_commonpathFunction · 0.72