Skip to content
This repository was archived by the owner on Feb 1, 2026. It is now read-only.

Commit 2918758

Browse files
Spacehunterzclaude
andcommitted
fix: Disable rate limiter and fix sys.path in backend tests
- Disable slowapi rate limiter during tests to prevent 429 errors - Add backend root to sys.path at module level for import resolution - Reset rate limiter storage between tests (fallback) Fixes: Rate limiting was causing 'ratelimit 3 per 1 minute exceeded' after first 3 auth tests, causing all subsequent tests to fail with 429. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 60580e6 commit 2918758

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

apps/dashboard/backend/tests/conftest.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import asyncio
99
import sqlite3
10+
import sys
1011
import tempfile
1112
import os
1213
import secrets
@@ -16,6 +17,11 @@
1617

1718
import pytest
1819

20+
# Ensure backend path is in sys.path for all tests
21+
BACKEND_ROOT = Path(__file__).parent.parent
22+
if str(BACKEND_ROOT) not in sys.path:
23+
sys.path.insert(0, str(BACKEND_ROOT))
24+
1925
try:
2026
import pytest_asyncio
2127
HAS_PYTEST_ASYNCIO = True
@@ -208,6 +214,14 @@ def app():
208214

209215
try:
210216
from main import app as fastapi_app
217+
218+
# Disable rate limiting for tests
219+
try:
220+
from routers.auth import limiter
221+
limiter.enabled = False
222+
except (ImportError, AttributeError):
223+
pass
224+
211225
return fastapi_app
212226
except ImportError as e:
213227
pytest.skip(f"Could not import FastAPI app: {e}")
@@ -412,7 +426,25 @@ def assert_security_headers(response):
412426

413427
@pytest.fixture(autouse=True)
414428
def cleanup_test_sessions():
415-
"""Automatically clean up test sessions after each test."""
429+
"""Automatically clean up test sessions and reset rate limiter after each test."""
430+
# Reset rate limiter BEFORE test runs
431+
try:
432+
from routers.auth import limiter
433+
# Clear the rate limiter storage
434+
if hasattr(limiter, '_storage'):
435+
limiter._storage.reset()
436+
elif hasattr(limiter, 'storage'):
437+
limiter.storage.reset()
438+
# For in-memory storage, clear the internal dict
439+
if hasattr(limiter, '_limiter') and hasattr(limiter._limiter, '_storage'):
440+
storage = limiter._limiter._storage
441+
if hasattr(storage, 'storage'):
442+
storage.storage.clear()
443+
elif hasattr(storage, '_storage'):
444+
storage._storage.clear()
445+
except (ImportError, AttributeError):
446+
pass # Rate limiter not available or different version
447+
416448
yield
417449

418450
try:

0 commit comments

Comments
 (0)