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

Function get_common_ancestor

src/_pytest/config/findpaths.py:205–228  ·  view source on GitHub ↗
(
    invocation_dir: Path,
    paths: Iterable[Path],
)

Source from the content-addressed store, hash-verified

203
204
205def get_common_ancestor(
206 invocation_dir: Path,
207 paths: Iterable[Path],
208) -> Path:
209 common_ancestor: Path | None = None
210 for path in paths:
211 if not path.exists():
212 continue
213 if common_ancestor is None:
214 common_ancestor = path
215 else:
216 if common_ancestor in path.parents or path == common_ancestor:
217 continue
218 elif path in common_ancestor.parents:
219 common_ancestor = path
220 else:
221 shared = commonpath(path, common_ancestor)
222 if shared is not None:
223 common_ancestor = shared
224 if common_ancestor is None:
225 common_ancestor = invocation_dir
226 elif common_ancestor.is_file():
227 common_ancestor = common_ancestor.parent
228 return common_ancestor
229
230
231def get_dirs_from_args(args: Iterable[str]) -> list[Path]:

Callers 5

test_simple_noiniMethod · 0.90
test_has_ancestorMethod · 0.90
test_single_dirMethod · 0.90
test_single_fileMethod · 0.90
determine_setupFunction · 0.85

Calls 2

commonpathFunction · 0.90
existsMethod · 0.45

Tested by 4

test_simple_noiniMethod · 0.72
test_has_ancestorMethod · 0.72
test_single_dirMethod · 0.72
test_single_fileMethod · 0.72