Test collection of non-python tests #13413
Unanswered
sashko1988
asked this question in
Q&A
Replies: 1 comment 5 replies
-
That indicates an misunderstanding and/or a missing cache we never knew we needed |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Strange performance struggle of pytest collection with non-python tests.
Any help appreciated!
Set up
Versions
Python 3.12.8
pytest 8.3.4
I use non-python tests. Let's assume it's a
yaml
file for this discussion.I followed the guide from the docs: https://docs.pytest.org/en/stable/example/nonpython.html, which was helpful. And tests are running without problems.
But collection is where pytest struggles.
A little bit about my setup:
-p
in the CLI.pytest_collection
hook wrapper, I pass resolved absolute paths intoconfig.args
and then run the main collection hook.Some code context:
How it struggles:
A lot of unnecessary file checks
Before it even starts creating test items, the main problem is that it iterates through the same files more than once. I added print statements for every file it checks in
pytest_collect_file
; some paths are repeated 193 times in the produced log for a suite with 1000k test files. Sometimes, those paths are not even tests that need to run.I run that 1000 suite with the profiler and
--collect-only
. The whole time was around 2 minutes. And according to the report,pytest_collect_file
ran for 42 seconds, and the actual collectionYamlFile.collect
took only 6 seconds.Log file contains 455k lines with paths that were checked in the
pytest_collect_file
.Different execution time depending from where pytest was called
The other problem is that I have a different execution time if I run pytest from the framework directory and any other folder.
The flow from the framework directory:
From any other folder:
Same args, same paths, but running from the root dir or test dir, it takes 38 seconds without the profiler / around 2 minutes with, and from the framework dir, it takes 23 minutes without the profiler.
The framework and test folders are subfolders of my home folder, on the same disk, which is a pretty fast SSD.
Same struggle with CI - I can't resolve tests, because pytest is called from the framework folder.
What can be the problem?
UPDATED
Profiler results and more info on
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. When I make the same call fromroot_working_folder
orrepo_with_tests
, the execution time is ~2 minutes.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:
Beta Was this translation helpful? Give feedback.
All reactions