Skip to content
Preptima
mediumScenarioConceptMidSeniorStaff

A test passes on your machine and fails in CI roughly once a week. How do you track it down?

5 min readUpdated 2026-08-15

Answer

Short answer

Make it reproducible before you make it pass. Pin the ordering seed, then work through the sources of non-determinism the test is exposed to - wall-clock time, global random state, hash-dependent iteration, real network calls and shared resources - and inject each one so the test controls it.

Was this answer helpful?

Likely follow-ups

  • Why is patching datetime.datetime.now harder than injecting a clock, and what do the libraries do instead?
  • How would you give each xdist worker its own database without a fixture rewrite?
  • When is a flaky test telling you the production code depends on ambient state?
  • How do you assert that a test suite never opens a socket?

Related questions

Further reading