Q1.Threads, processes or asyncio: which do you choose for test workloads?
Short answer: it depends on what the work waits for.
- asyncio - many network calls (seeding data, polling APIs) in one process.
- Threads - blocking I/O libraries that have no async version.
- Processes - CPU-heavy work, or full isolation between tests. pytest-xdist uses separate worker processes.
The reason: in standard CPython the GIL lets only one thread run Python bytecode at a time, so threads help with waiting, not with CPU work. (Python 3.13 added an optional free-threaded build, but it is experimental.)
- Why does pytest-xdist use processes rather than threads?
