"""Shared fixtures for the finance test suite. The AI-spending service caches its canonical ``_collect_period_rows`` result in a module-global keyed by ``(period_start, period_end_excl)`` with a 60s TTL. Finance tests drive the AI collector (via the spend coordinator) with DIFFERENT data for the SAME period across tests, so that cache leaks between tests — one test's empty AI window would be served to the next test that seeded real AI cost. Invalidate it around every finance test so each runs against a clean cache. """ from __future__ import annotations import pytest @pytest.fixture(autouse=True) def _invalidate_ai_period_cache(): from app.domains.ai_spending.service import invalidate_period_rows_cache invalidate_period_rows_cache() yield invalidate_period_rows_cache()