A test passes locally but fails in CI only when run with the rest of the suite. What do you suspect?
IntermediateScenarioTesting, CI/CD, packaging & services
Answer
Situation read → Test pollution: shared state leaking between tests.
What I'd do →
- Run with random order (
pytest-randomly) and bisect:pytest -p no:randomly tests/test_a.py tests/test_b.py. - Look for module-level state, singletons, cached clients created at import, env vars set without
monkeypatch, and files written outsidetmp_path. - With moto, look for clients created outside
mock_aws(they hit real endpoints or a different mock).
Why → Order-dependent tests are always shared-state bugs.
Interview tip → Mention clients created at import time, a frequent moto pitfall.
More on Testing, CI/CD, packaging & services
You join a team whose Python automation repo has no tests. Where do you start?BeginnerYour pytest suite takes 12 minutes. How do you speed it up?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