To reduce automated test execution time, measure where the elapsed time goes, then speed up the dominant part: run independent tests concurrently, distribute work across CI jobs when one machine is the bottleneck, and use changed-test runs only for preliminary feedback. Keep full-suite runs as a correctness check, and fix flaky tests that trigger repeat work.
Start by finding the real bottleneck
Record wall-clock time for a representative local run and a CI run. Where your runner provides them, collect durations by test or file as well. Separate time spent executing tests from setup and teardown, waiting on external services, environment startup, and CI scheduling. The right optimization depends on which part dominates: adding workers will not help much if the suite is mostly waiting on a shared service or spending time provisioning the environment.
As an Amazon Associate I earn from qualifying purchases.
Use the same commit, test selection, and comparable machine conditions when comparing runs. Track both elapsed time and whether failures or reruns increase. The aim is faster dependable feedback, not merely a lower number from one run.
Run independent tests in parallel
pytest with pytest-xdist
pytest-xdist distributes pytest tests across worker processes. A straightforward starting point is:
pytest -n auto
The auto setting uses the number of physical CPU cores to choose workers. Treat that as a starting point, not an optimal setting for every suite. Try a bounded worker count as well, then compare elapsed time, resource contention, and failure stability. Tests dominated by network waits may respond differently from CPU-heavy tests, and worker processes also consume memory and other shared resources.
Playwright workers
Playwright supports running test files in parallel. Its parallelism documentation gives --workers 4 as an example and notes that parallel test files do not have a guaranteed order: Playwright parallelism.
For CI, Playwright recommends one worker to prioritize stability and reproducibility. It also notes that parallel execution may suit powerful self-hosted systems. Follow that guidance in context: benchmark your environment and avoid raising the worker count simply because the option exists. A worker setting that improves local feedback may create resource contention or instability on a smaller CI runner.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
When to use more workers and when to shard
More workers run concurrent work on the same machine; sharding splits the suite across separate CI jobs or machines. Playwright documents sharding as a way to distribute tests across CI jobs. Consider it when one runner is the limiting factor and the tests can run independently.
| Approach | What it changes | Trade-off to check |
|---|---|---|
| More workers on one runner | Runs more tests concurrently on that machine. | Can hit CPU, memory, or shared-service limits and expose test dependencies. |
| Sharding across CI jobs | Distributes test work across multiple runners. | Can reduce elapsed time but increase total compute use and setup overhead; reports and failure ownership can become more complex. |
Compare wall-clock time, total CI resource consumption, setup costs, and the effort needed to combine results. Sharding is not automatically faster if job startup or uneven shard sizes dominate the run.
Use changed-test runs for an early signal, not as a replacement
Running tests associated with changed files can shorten the first feedback loop. But selection is a heuristic: Playwright warns that it may miss relevant tests. Use it as a preliminary signal and follow it with the full suite when validating a change, rather than treating the selected run as equivalent coverage. See Playwright’s CI guidance.
Rank #4
Make parallel execution safe
Concurrency changes timing and execution order, which can expose hidden assumptions. pytest’s documentation identifies shared system state, missing cleanup, and order dependencies as contributors to flaky tests, including under parallel execution: pytest: flaky tests.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minute- Give each test isolated data and resources where possible; avoid concurrent tests modifying the same record, file, account, or service state.
- Make setup and teardown self-contained. Do not rely on another test to prepare or clean up state.
- Remove order dependencies and uncontrolled global state so a test can run independently.
- When parallel runs fail, investigate whether the failure is a genuine product defect, a resource limit, or a test-isolation problem before increasing retries or worker counts.
Flaky failures cost time because teams rerun suites and investigate spurious results. The documentation describes that repeat work but does not quantify a general time saving from fixing flakes.
Best Value
A practical optimization sequence
- Baseline: Record representative local and CI wall-clock times and available per-test or per-file durations.
- Diagnose: Identify whether execution, setup, waiting, environment startup, or scheduling is the dominant cost.
- Change one thing: Try a worker setting for independent tests, or shard across jobs if a single runner is the constraint.
- Validate: Compare elapsed time, resource use, and failure behavior against the baseline on comparable runs.
- Stabilize: Fix shared state, cleanup, and ordering problems revealed by concurrency before scaling it further.
- Shorten initial feedback carefully: Use changed-test selection if useful, while retaining a full-suite correctness run.
Or skip the browser setup
If your automated tests need website screenshots, ScreenshotNeo offers a one-request alternative to managing a browser capture setup. Its API can return an image or PDF, and the parameter names used by other screenshot APIs also work. See the ScreenshotNeo API documentation.
Quick Recap
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo accepts cookie or consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses include X-Page-Verdict and X-Billed headers. Its MCP server includes take_screenshot, get_page_info, and capture_pdf for AI agents. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.
Sign up for ScreenshotNeo free.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →




