Interview Prep/Python for DevOps/Testing, CI/CD, packaging & services

Your pytest suite takes 12 minutes. How do you speed it up?

IntermediateScenarioTesting, CI/CD, packaging & services
Answer

Situation read → Usually network calls, sleeps, or expensive setup repeated per test.

What I'd do →

  1. pytest --durations=20 to find the slowest tests.
  2. Remove real network and time.sleep (mock clocks, mock retries, set backoff to zero in tests).
  3. Widen fixture scope for expensive, read-only setup (session-scoped containers).
  4. Run in parallel with pytest-xdist (-n auto), ensuring tests are independent.
  5. Split slow integration tests behind a marker (-m "not integration") for PRs.

Why → Most slow suites are a few slow tests; measure first.

Interview tip → --durations is the first command to name.

All Python for DevOps questions Roadmap: Python for automation

More on Testing, CI/CD, packaging & services