🔨 Run tests with `pytest-xdist` and `pytest-cov` by YuriiMotov · Pull Request #14992 · fastapi/fastapi
Tests run x2.3 faster (locally): 18s VS 42s.
The drawback is that it's easy to introduce race condition. We need to be careful and mark tests that modify files in working directory with @workdir_lock decorator introduced in this PR.
To make it easier to debug race conditions, I added pytest-timeout plugin.
Stress-tested with -n 50 - adjusted pytest timeout as a result (5 -> 20).
After all adjustments, 10 runs passed ✅
Note: I added test-cov.sh script and moved --cov --cov-context=test to it. This way when we run just test.sh it works much faster (doesn't store coverage data).
Inline snapshot gives the following:
INFO: inline-snapshot was disabled because you used xdist. This means that tests with snapshots will continue to run, but snapshot(x) will only return x and inline-snapshot will not be able to fix snapshots or generate reports.
To update inline snapshots we can run tests as bash scripts/test.sh -n 0