Running a simple pytest -k nomatchingtestfilter takes around 2-3 seconds on my Ubuntu 22.04 machine just on the collecting... stage.
I have custom pytest_collection and pytest_collection_modify_items functions in conftest.py. I added a print(start - end) log inside them (start and end are set to time.time()). From this log, I know they only take a few milliseconds to execute. I do not have any other user-defined functions related to pytest collection.
Therefore, I need to profile the collection step to understand why exactly it is taking 2-3 seconds to collect a few hundred parameterized tests.
I tried pytest-profiling, but it does not help because it starts profiling after the collection is done.
Question: What is the way to profile the pytest collection step so as to find bottlenecks and improve their speed?
I don't have a specific suggestion for profiling, but I have found that a large amount of files (even non-Python files) within your project can cause slow collection. See this similar question
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With