"""Shared fixtures for web route tests. The Flask-Limiter ``limiter`` is a module-level singleton whose in-memory storage is attached once at ``create_app()`` time and never reset between tests. Without intervention the per-scope request counters (notably the shared ``settings`` scope, "30 per minute") accumulate across every test in the process that hits a rate-limited route — so unrelated tests that make their 31st settings request in a 60-second window get an unexpected HTTP 429 instead of the status they assert. The failing set is non-deterministic because it depends on how many sibling requests landed in the trailing window. Resetting the storage before each test gives every test a clean bucket without disabling enforcement, so rate-limiting tests (test_settings_routes_rate_limiting.py) still exercise real limits from a known-clean starting point. """ import pytest @pytest.fixture(autouse=True) def _reset_rate_limiter_storage(): """Clear the global limiter's storage before each route test.""" try: from local_deep_research.security.rate_limiter import limiter storage = getattr(limiter, "_storage", None) if storage is not None and hasattr(storage, "reset"): storage.reset() except Exception: # Limiter not importable / no storage yet → nothing to reset. pass yield