You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(tests): test_review_fixes.py rate-limit env patch applied after client fixture, making test a false positive #268
test_review_fixes.py patches RATE_LIMIT_DEFAULT_PER_MINUTE via monkeypatch.setenv() and calls get_settings.cache_clear() inside the test body — but the client fixture is already fully resolved before the test body runs. The rate limiter in the client always sees the original (high) limit, so the 429 assertion never actually triggers. The test is a false positive that permanently passes while verifying nothing.
Root Cause
tests/test_review_fixes.py around line 54:
deftest_rate_limit_kicks_in_after_one_request(client, monkeypatch):
monkeypatch.setenv('RATE_LIMIT_DEFAULT_PER_MINUTE', '1') # ← too lateget_settings.cache_clear() # ← too later1=client.get('/v1/health')
r2=client.get('/v1/health')
assertr2.status_code==429# ← never reached, r2 is 200
The client fixture creates the FastAPI TestClient using create_app(get_settings())beforemonkeypatch.setenv runs. The rate limiter captured limit=60 at fixture construction time.
Failure Scenario
test_rate_limit_kicks_in_after_one_request runs.
client fixture builds the app with rate_limit=60.
Test body patches env var and clears cache — no effect on the already-built app.
OR: test passes via prior-test contamination from a previous test that set a low limit — making the pass order-dependent and non-deterministic.
Proposed Fix
Move the env patch to a fixture that runs BEFORE the client fixture is resolved:
@pytest.fixturedeflow_rate_limit_client(monkeypatch):
monkeypatch.setenv('RATE_LIMIT_DEFAULT_PER_MINUTE', '1')
get_settings.cache_clear()
# Now create the client AFTER the env is patched:app=create_app(get_settings())
withTestClient(app) asc:
yieldcdeftest_rate_limit_kicks_in_after_one_request(low_rate_limit_client):
r1=low_rate_limit_client.get('/v1/health')
r2=low_rate_limit_client.get('/v1/health')
assertr1.status_code==200assertr2.status_code==429
Activity
piyushmakhija28 commentedon Jun 21, 2026
Fixed in PR #280 (Sprint R3/R4: fix(sprint-r3): root-cause fixes for all 39 bugs from code review round 3 + Sprint R4 round 4)