import pytest from apps.accounts.middleware import SetupWizardMiddleware @pytest.fixture(autouse=True) def _reset_setup_wizard_cache(): """SetupWizardMiddleware caches "does any User exist" on the class itself (not per-request), so it survives across tests in the same pytest process regardless of Django's per-test DB rollback. Autouse and global (not scoped to apps/accounts/tests.py) so no test file can leak a stale True into another — a test exercising "no user exists yet" behavior must actually start from that state, not from whatever an earlier, unrelated test happened to leave behind. """ SetupWizardMiddleware._a_user_exists = False yield SetupWizardMiddleware._a_user_exists = False