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 →
pytest --durations=20to find the slowest tests.- Remove real network and
time.sleep(mock clocks, mock retries, set backoff to zero in tests). - Widen fixture scope for expensive, read-only setup (session-scoped containers).
- Run in parallel with
pytest-xdist(-n auto), ensuring tests are independent. - 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.
More on Testing, CI/CD, packaging & services
You join a team whose Python automation repo has no tests. Where do you start?BeginnerA test passes locally but fails in CI only when run with the rest of the suite. What do you suspect?IntermediateYou want a reusable CI pipeline for 15 Python tool repos. What goes in it?IntermediateYour Python Docker image is 1.1 GB. How do you shrink it?IntermediateYou want to distribute an internal CLI to 200 engineers. What are your options?IntermediateA Flask app runs with `app.run()` in production and falls over under load. What do you change?Beginner