Disable rate_limit_redis_enabled in test fixtures
CI / lint (pull_request) Successful in 8s
CI / typecheck (pull_request) Failing after 33s
CI / test (pull_request) Failing after 33s
CI / build-and-push (pull_request) Has been skipped

The rate-limit middleware creates a Redis client at module import time
when rate_limit_redis_enabled is true. The conftest disables
rate_limit_enabled but not the redis flag, so the client still gets
created. After the test event loop closes, the client's async
disconnect raises 'Event loop is closed', surfacing as 500s on
test_validation_error_returns_422_with_field_errors and
test_error_stats_with_valid_key.

Setting rate_limit_redis_enabled=False in the autouse fixture prevents
the Redis client from being created in the first place.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Barcode Betty
2026-06-02 13:38:06 +00:00
parent 3eb11543b5
commit ce23ee18b8
+2
View File
@@ -142,8 +142,10 @@ TEST_DATABASE_URL = "sqlite+aiosqlite:///:memory:"
def disable_rate_limiting():
"""Disable rate limiting for all tests to prevent 429 interference."""
cartsnitch_settings.rate_limit_enabled = False
cartsnitch_settings.rate_limit_redis_enabled = False
yield
cartsnitch_settings.rate_limit_enabled = True
cartsnitch_settings.rate_limit_redis_enabled = True
@pytest.fixture