-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Slow collection time when tests are not in a relative folder to the current working folder #13420
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
Labels
topic: collection
related to the collection phase
type: performance
performance or memory problem/improvement
Comments
patchback bot
pushed a commit
that referenced
this issue
May 16, 2025
…3422) * add lru_cache to nodes._check_initialpaths_for_relpath update tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Oleksandr Zavertniev <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> (cherry picked from commit cfbe319)
nicoddemus
pushed a commit
that referenced
this issue
May 16, 2025
…3422) (#13425) * add lru_cache to nodes._check_initialpaths_for_relpath update tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- (cherry picked from commit cfbe319) Co-authored-by: Sashko <[email protected]> Co-authored-by: Oleksandr Zavertniev <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@RonnyPfannschmidt, any info when this will be released? |
The next patch release will include it |
Tusenka
pushed a commit
to Tusenka/pytest
that referenced
this issue
May 24, 2025
…elpath (pytest-dev#13422) * add lru_cache to nodes._check_initialpaths_for_relpath update tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Oleksandr Zavertniev <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
topic: collection
related to the collection phase
type: performance
performance or memory problem/improvement
Created after this discussion - #13413
OSes, python and pytest versions
OS: macOS 15.4.1, Ubuntu 22.04
Python 3.12.8
Pytest 8.3.4
Problem description
I need to execute a lot of non-python tests that are stored in folders with lots of nesting. And I found that Pytest struggles during the collection.
Some code context:
Consider this folder structure:
But even more subfolders in
repo_with_tests
Pytest call is the following:
pytest --collect only ${list with 1k non-python tests}
. (1 test per file)When I execute the above from
framework_internal_folder
, the execution time is 56 minutes withcProfile
, 23 minutes without. When I make the same call fromroot_working_folder
orrepo_with_tests
, the execution time is ~2 minutes with withcProfile
/ 38 seconds without.The most significant time difference in the two calls is in the cumulative time of that function -
nodes.py:546(_check_initialpaths_for_relpath)
According to stats, when executing from framework_internal_folder, the most struggling function is here:
Possible solutions
Cache for
_check_initialpaths_for_relpath
I experimented with adding
lru_cache
to_check_initialpaths_for_relpath
:That change decreased the overall collection time to 4 minutes.
Stats are also impressive:
I'm not sure if
commonpath
needs caching as well.Anything else on the collection mechanism?
Other optimizations in directory/file collections
The text was updated successfully, but these errors were encountered: