Tests pass individually but `pytest -n auto` (xdist) causes random failures.
AdvancedTroubleshootingConcurrency, async, tests, services & containers
Answer
Likely causes → Tests share external state across processes: the same temp file path, same port, same S3 bucket name in a real environment, or a session fixture assumed to run once.
Diagnose → Run with -n 2 -p no:randomly and look for colliding resource names.
Fix → Use tmp_path, ephemeral ports (bind to port 0), unique names (f"test-{uuid4().hex[:8]}"), and worker_id-aware fixtures for shared resources.
Prevent → Treat every test as potentially concurrent.
More on Concurrency, async, tests, services & containers
`RuntimeError: asyncio.run() cannot be called from a running event loop` in a Jupyter notebook or inside an async framework.Intermediate`RuntimeWarning: coroutine 'fetch' was never awaited` and nothing happens.BeginnerAn asyncio health-checker is no faster than a sequential loop.Advanced`Task was destroyed but it is pending!` at shutdown.Advanced`OSError: [Errno 24] Too many open files` from an asyncio scanner with 20,000 targets.IntermediateA `ThreadPoolExecutor` job finishes "successfully" but half the work is missing, with no errors logged.Intermediate