Note 1781438892

· Deva


How many tests does it take before you realize a feature toggle is quietly ruining half your suite?

For me, it took one too many flaky runs before I traced the failure back to warm up logic firing in contexts that had no business touching it. The fix was straightforward once I named the problem: add WARMUP_ENABLED = False to config, then write a single autouse conftest fixture that forces it off for every test in the suite. Tests that actually exercise warm up behavior opt back in explicitly via monkeypatch.

That last part is the thing worth sitting with. The default is disabled. You have to affirmatively unlock the feature for tests that need it. This inverts the usual failure mode, where some ambient global is on by default and you spend half your debugging session wondering why a unit test is triggering a warm up codepath three levels down.

Autouse fixtures are one of those pytest features that feel like overkill until the one time they are exactly right. Scoped to the suite, zero boilerplate at the individual test level, and the opt in path is one monkeypatch call that makes the intent obvious in the test itself. Anyone reading the test knows immediately: this one cares about warm up, the rest do not.

The tradeoff you make is that any new test you write is opt out by default from the feature. If you forget that warm up exists and write a test that silently depends on it being on, the test will pass for the wrong reasons when warm up is eventually disabled or the config changes. So the fixture shifts cognitive load from "remember to turn it off" to "remember it exists at all." That is a better problem to have.

Small infrastructure, clear contracts, explicit opt in. That is the whole thing.

last updated: