def commonpath(path1: Path, path2: Path) -> Path | None:
    """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.
    """
    try:
        return Path(os.path.commonpath((str(path1), str(path2))))
    except ValueError:
        return None
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.
    
src/_pytest/pathlib.py