test: suppress expected error logs in SSE test

Use pytest's caplog fixture to suppress ERROR logs when deliberately
triggering errors in test_sse_generator_error_before_response_starts.
This keeps test output clean while still validating error handling behavior.
This commit is contained in:
Ashwin Bharambe 2025-10-21 12:00:59 -07:00
parent cb2185b936
commit 62626d4d94
5 changed files with 60 additions and 17 deletions

View file

@ -4,6 +4,7 @@
# This source code is licensed under the terms described in the LICENSE file in
# the root directory of this source tree.
import logging # allow-direct-logging
from uuid import uuid4
import pytest
@ -17,6 +18,12 @@ from llama_stack.core.storage.datatypes import KVStoreReference, SqliteKVStoreCo
from llama_stack.providers.utils.kvstore import register_kvstore_backends
@pytest.fixture
def suppress_quota_warnings(caplog):
"""Suppress expected WARNING logs for SQLite backend and quota exceeded"""
caplog.set_level(logging.CRITICAL, logger="llama_stack.core.server.quota")
class InjectClientIDMiddleware(BaseHTTPMiddleware):
"""
Middleware that injects 'authenticated_client_id' to mimic AuthenticationMiddleware.
@ -70,13 +77,13 @@ def auth_app(tmp_path, request):
return app
def test_authenticated_quota_allows_up_to_limit(auth_app):
def test_authenticated_quota_allows_up_to_limit(auth_app, suppress_quota_warnings):
client = TestClient(auth_app)
assert client.get("/test").status_code == 200
assert client.get("/test").status_code == 200
def test_authenticated_quota_blocks_after_limit(auth_app):
def test_authenticated_quota_blocks_after_limit(auth_app, suppress_quota_warnings):
client = TestClient(auth_app)
client.get("/test")
client.get("/test")
@ -85,7 +92,7 @@ def test_authenticated_quota_blocks_after_limit(auth_app):
assert resp.json()["error"]["message"] == "Quota exceeded"
def test_anonymous_quota_allows_up_to_limit(tmp_path, request):
def test_anonymous_quota_allows_up_to_limit(tmp_path, request, suppress_quota_warnings):
inner_app = FastAPI()
@inner_app.get("/test")
@ -107,7 +114,7 @@ def test_anonymous_quota_allows_up_to_limit(tmp_path, request):
assert client.get("/test").status_code == 200
def test_anonymous_quota_blocks_after_limit(tmp_path, request):
def test_anonymous_quota_blocks_after_limit(tmp_path, request, suppress_quota_warnings):
inner_app = FastAPI()
@inner_app.get("/test")