Pytest optimization
Pytest is very slow. Seems like docker compose -f dev.yml run --rm api pytest /sometest
load all the fixture in conftest.py
and this is what take a looot of time. I investigated a little and I think it's specifically the factories related fixtures that take a long time. Commenting this 5 fixture the load time of the test env goes from 60s to less than 1...
factories
preferences
logged_in_client
superuser_api_client
logged_in_api_client
https://docs.pytest.org/en/6.2.x/cache.html#the-new-config-cache-object https://docs.pytest.org/en/6.2.x/reference.html#std-fixture-cache
I tried mounting the pytest cache into the api container but it doesn't speedup the process. Fixture are suppose to be cache tho' : https://docs.pytest.org/en/6.2.x/fixture.html#fixtures-can-be-requested-more-than-once-per-test-return-values-are-cached. Maybe the issue comes from the fact that the register is a generator ?
In some case --reuse-db
can be usefull.
ref : !2317 (comment 61277)