Track: test automation in depth · Lesson 32 of 41 · 16 min

A stable, fast automated test suite: isolation, parallelism, retries, selective runs

How to keep a suite of hundreds of tests green and fast: independent tests, parallel runs, a retry policy, quarantine and running only what's needed.

The suite is a product

An automated test suite is code that ages, slows down and breaks too. Two metrics show its health: the share of flaky tests and time to feedback (how long a developer waits after a push).

Automated test suite health (illustrative)Flaky, %7%Before1%AfterRun time, min38Before9After
Automated test suite health (illustrative). Example: after isolating data and running in parallel, the flaky share dropped from 7% to 1% and feedback time from 38 to 9 minutes. The numbers are illustrative.

Isolation comes first

A test is isolated if it can run on its own, in any order and in parallel with others. The check is simple:

pytest -p no:randomly          # normal order
pytest -p randomly             # random order (pytest-randomly)
pytest -n 8                    # 8 workers (pytest-xdist)

If the results differ, tests depend on each other: shared data, global state, order. The cure: data through function-scoped fixtures, unique prefixes, and no "test 2 uses what test 1 created".

Parallelism

Level How Gain
Workers on one machine pytest -n auto, workers in Playwright ×2–8
Shards across machines --shard in CI ×N machines
Split by type API separately from UI API gives a fast signal first

Parallelism is limited by shared resources: one test user, one mailbox, an API rate limit. Build a resource pool or create your own per worker.

Retries: a band-aid, not a cure

  • Allowed: 1 retry in CI for UI tests, with each retry logged.
  • A test that passed only on retry is marked flaky in the report.
  • API tests usually don't need retries — instability there is almost always a defect.

Quarantine

@pytest.mark.quarantine(reason="BUG-311 flaky on CI, owner: anna, until 2026-12-05")
def test_export_large_report(...): ...

The quarantine set runs as a separate job, doesn't block merges, and has an owner and a deadline. An empty quarantine is the sign of a healthy suite.

Run only what's needed

  • Tags: smoke on every PR, full regression nightly.
  • Code changes: if only the cart module changed, run the cart tests and the end-to-end ones (test impact analysis with a "module → tests" map).
  • Priorities: critical first, then the rest — a fast signal on what matters most.

It's the same principle as for manual suites: smoke = critical + high, regression = everything by priority — see levels and types of testing.

Speed of a single test

  • Prepare data through the API, not the UI.
  • Log in through the API and reuse the session state (storageState in Playwright).
  • No sleep — only waits for a state.
  • Don't recheck in a UI test what API tests already cover.

Suite metrics

Track over the last 30 days: the flaky share, the median and p95 run time, the number of quarantined tests, the 10 slowest tests. Each test's history across runs is visible in the Autotests section of QA Tools.

Key takeaways

  • An isolated test passes alone, in random order and in parallel.
  • A retry is a temporary, logged band-aid; a test that passes only on retry is flaky.
  • Run what's needed: smoke on PRs, regression nightly, changed modules' tests first.

Check yourself

  1. 1. Tests pass sequentially but fail with pytest -n 8. The most likely cause?

  2. 2. How should you treat a test that passes only on the second attempt?

  3. 3. What must a quarantined test have?

Practice: Automation architecture and flaky tests