Manuals / Playwright with Python / Chapter 30
Part 4 · Advanced Techniques · advanced · ~40 min · Chapter 30 of 61
22. Parallel Execution & Sharding
pytest-xdist for parallel runs pip install pytest-xdist pytest -n 4 # run using 4 parallel workers pytest -n auto # auto-detect CPU core count pytest -n <count> What it does: Distributes tests across multiple worker processes running in parallel instead of sequentially. Types/params: ● <count> (integer or "auto") — number of parallel workers; "auto" picks based on available CPU cores Pointers: Spe
Step 1 of 2
Overview
What it does: Distributes tests across multiple worker processes running in parallel instead of sequentially. Types/params: Pointers: Speed gains are significant but not linear — too many workers on too few CPU cores causes contention that can actually slow things down (ties into Chapter 32's performance tuning). Tests must be properly isolated (no shared mutable state, no fixed ports/files) or parallel execution surfaces race conditions that don't show up running sequentially.
Try it
Run / study this snippet
pytest-xdist for parallel runsChapter learning outcomes
- Sharding tests across machines/CI runners
Clear these before you leave
Side quest
22. Parallel Execution & Sharding deliverable
Apply one idea from “Overview” in a small script or note.