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

Path progress
48%

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.

OverviewDrag stickies · tap for tips
Study mapDrag stickies · tap for tipsKeep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Assert the UIdrag · tap →Retry wiselydrag · tap →Seed datadrag · tap →Close the loopdrag · tap →Keep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Pathwise hackdrag · tap →Page under testdrag · tap →Multi-browserdrag · tap →Automation pathdrag · tap →Tooling nodedrag · tap →

Try it

Run / study this snippet

pytest-xdist for parallel runs
Was this step clear?
Chapter 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.