FastAPICache.init() starts with if cls._init: return. The first call in a pytest session wins and every later call is a silent no-op.
Two consequences:
-
_create_server() re-inits the cache per test, but that does nothing after the first test — so the in-memory store is shared for the whole session and a cached route can serve a previous test's response. Hit this while adding coverage for GET /v0/solar/GB/status: the second test got the first one's payload. Existing tests hid it because their second case 404s, and exceptions aren't cached.
-
The ~25 FastAPICache.init(InMemoryBackend(), prefix="test") / prefix="cold" calls in src/quartz_api/internal/service/v1/test_router.py are all no-ops. They neither set the prefix nor provide a fresh backend. The cold-cache 503 tests are not actually starting from a cold cache — they pass on session ordering rather than on the isolation they look like they're asserting.
Fix: autouse fixture in src/quartz_api/internal/service/conftest.py clearing the backend between tests, then drop the no-op init calls in test_router.py.
@pytest_asyncio.fixture(autouse=True)
async def clear_cache():
if FastAPICache._init:
await FastAPICache.clear()
yield
Verified: with this in the shared conftest the full unit suite passes (223 passed) with no exceptions needed — including the v1 cold-cache tests, which get a genuinely cold cache rather than an accidental one. FastAPICache.reset() is also available if a test wants a full re-init.
Interim: test_status_router.py carries a local copy of this fixture. Remove it as part of the fix.
FastAPICache.init()starts withif cls._init: return. The first call in a pytest session wins and every later call is a silent no-op.Two consequences:
_create_server()re-inits the cache per test, but that does nothing after the first test — so the in-memory store is shared for the whole session and a cached route can serve a previous test's response. Hit this while adding coverage forGET /v0/solar/GB/status: the second test got the first one's payload. Existing tests hid it because their second case 404s, and exceptions aren't cached.The ~25
FastAPICache.init(InMemoryBackend(), prefix="test")/prefix="cold"calls insrc/quartz_api/internal/service/v1/test_router.pyare all no-ops. They neither set the prefix nor provide a fresh backend. The cold-cache 503 tests are not actually starting from a cold cache — they pass on session ordering rather than on the isolation they look like they're asserting.Fix: autouse fixture in
src/quartz_api/internal/service/conftest.pyclearing the backend between tests, then drop the no-opinitcalls intest_router.py.Verified: with this in the shared conftest the full unit suite passes (223 passed) with no exceptions needed — including the v1 cold-cache tests, which get a genuinely cold cache rather than an accidental one.
FastAPICache.reset()is also available if a test wants a full re-init.Interim:
test_status_router.pycarries a local copy of this fixture. Remove it as part of the fix.