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

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 →

  1. Run with random order (pytest-randomly) and bisect: pytest -p no:randomly tests/test_a.py tests/test_b.py.
  2. Look for module-level state, singletons, cached clients created at import, env vars set without monkeypatch, and files written outside tmp_path.
  3. 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.

All Python for DevOps questions Roadmap: Python for automation

More on Testing, CI/CD, packaging & services