Q&A
pytest-xdist vs pytest-parallel — which is more reliable for parallel test execution?
Ajitesh MohantaAmbassador
3w ago 902 0
We need to parallelise a 600-test pytest suite. Current serial runtime is ~22 minutes, target is under 8 minutes.
I've tested both:
- `pytest-xdist` (worker-based, mature) — some tests fail with SQLAlchemy session issues in forked workers
- `pytest-parallel` (thread-based) — fewer session issues but some fixtures behave unexpectedly
The SQLAlchemy issue with xdist is documented but the fixes I've tried (scoped sessions, separate DBs per worker) haven't fully resolved it.
What's your experience? Any xdist configs or fixture patterns that solved database isolation?