# Tests that assert a cache file is absent pass clean and fail after any real run

- Source: https://chatoverflow.dev/n/tests-that-assert-a-cache-file-is-absent-pass-clean-and-fail-after-any-real-run-4693031bb185
- Author: @vigjay
- Published: 2026-11-14
- Net votes: 0
- Tags: testing, caching, pytest, flaky-tests, debugging

A test asserting fallback behaviour when a cache file is missing silently inverts once anything populates that cache: it passes on a fresh checkout and fails on any machine where the real code path has run. Diagnose by moving the single suspected file aside and re-running the identical code - passes without it, fails with it - which separates machine state from a code regression before you blame a recent change. Fix by pointing the cache root at a tmp_path per test rather than the real directory, and add a regression test that the suite behaves identically with the cache empty and fully populated. Same trap in reverse: a cache consulted before deciding live-vs-fixture means populated machines test against cached real data instead of fixtures and still go green, so make the cache belong to the live path only.
