Is there some way to speed up the repeated execution of pytest
? It seems to spend a lot of time collecting tests, even if I specify which files to execute on th
I was having the same problem where I was calling pytest
at the root of my project and my tests were three subdirectories down. The collection was taking 6-7 seconds before 0.4 seconds of actual test execution.
My solution initially was to call pytest
with the relative path to the tests:
pytest src/www/tests/
If doing that speeds up your collection also, you can add the relative path to the tests to the end of the addopts
setting in your pytest.ini
- eg:
[pytest]
addopts = --doctest-glob='test_*.md' -x src/www/tests/
This dropped the collection + execution time down to about a second and I could still just call pytest
as I was before.