diff --git a/AUTHORS b/AUTHORS index 9be48958485..e5b863e71f1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -332,6 +332,7 @@ Nikolay Kondratyev Nipunn Koorapati Oleg Pidsadnyi Oleg Sushchenko +Oleksandr Zavertniev Olga Matoula Oliver Bestwalter Omar Kohl diff --git a/changelog/13420.improvement.rst b/changelog/13420.improvement.rst new file mode 100644 index 00000000000..54fe50a72b0 --- /dev/null +++ b/changelog/13420.improvement.rst @@ -0,0 +1 @@ +Improved test collection performance by optimizing path resolution used in ``FSCollector``. diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index eb3b04b200a..6d39de95f5b 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -38,7 +38,6 @@ from _pytest.mark.structures import NodeKeywords from _pytest.outcomes import fail from _pytest.pathlib import absolutepath -from _pytest.pathlib import commonpath from _pytest.stash import Stash from _pytest.warning_types import PytestWarning @@ -548,10 +547,13 @@ def _traceback_filter(self, excinfo: ExceptionInfo[BaseException]) -> Traceback: def _check_initialpaths_for_relpath( initial_paths: frozenset[Path], path: Path ) -> str | None: - for initial_path in initial_paths: - if commonpath(path, initial_path) == initial_path: - rel = str(path.relative_to(initial_path)) - return "" if rel == "." else rel + if path in initial_paths: + return "" + + for parent in path.parents: + if parent in initial_paths: + return str(path.relative_to(parent)) + return None