Skip to content

Improvement: #13420 - Update logic of nodes._check_initialpaths_for_relpath #13448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ Nikolay Kondratyev
Nipunn Koorapati
Oleg Pidsadnyi
Oleg Sushchenko
Oleksandr Zavertniev
Olga Matoula
Oliver Bestwalter
Omar Kohl
Expand Down
1 change: 1 addition & 0 deletions changelog/13420.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved test collection performance by optimizing path resolution used in ``FSCollector``.
12 changes: 7 additions & 5 deletions src/_pytest/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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


Expand Down