pytest-xdist crashed worker: debugging
Debugs pytest-xdist worker crashes: isolation, -p no:cacheprovider, and faulty tests. Use when xdist workers crash. Not for slow parallel runs.
TL;DR
xdist workers crash from the same causes as serial runs plus shared-state interference. Run with -p no:xdist to confirm parallelism is the trigger, then bisect to the crashing test.
Error
worker 'gw2' crashed while running test_xSteps
- Run without xdist:
pytest -p no:xdist. Expected: if it passes, parallelism is the trigger. - Run with
-n2and--dist loadfileto change distribution. Expected: narrows whether it is load-related. - Bisect: run half the suite with xdist until one file crashes a worker. Expected: the crashing file found.
- Check that file for segfault causes: native extensions, huge memory, fork-unsafe code. Expected: the killer identified.
- Fix or mark that file
run_in_serial(via plugin) and restore parallelism. Expected: green at full speed.
When to use
worker crashedwith xdist.- Crashes that vanish without
-n.
When not to use
- Slow but stable parallel runs (tuning, not crashes).
- Collection errors (happen before workers).
Tool compatibility
- pytest 7/8; pytest-xdist.
Variant phrasings
xdist worker died
Same event; bisect to the file.
gw0 crashed
The worker-named form.
Why it happens
Workers are separate processes sharing nothing, but the tests may assume shared state (files, ports, DBs), and one bad test kills its worker.
Edge cases
--dist loadscopekeeps classes together; fixes some interference.- Each worker needs its own DB schema or the tests collide.
-p no:cacheprovideravoids cache races between workers.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst6UO536gyAmvILiYW3NVhg
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.