mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-12 20:12:33 +00:00
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:
parent
cb2185b936
commit
62626d4d94
5 changed files with 60 additions and 17 deletions
|
|
@ -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 unittest.mock import AsyncMock, patch
|
||||
|
||||
import httpx
|
||||
|
|
@ -15,6 +16,13 @@ from llama_stack.core.datatypes import AuthenticationConfig, AuthProviderType, G
|
|||
from llama_stack.core.server.auth import AuthenticationMiddleware
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def suppress_auth_errors(caplog):
|
||||
"""Suppress expected ERROR logs for tests that deliberately trigger authentication errors"""
|
||||
caplog.set_level(logging.CRITICAL, logger="llama_stack.core.server.auth")
|
||||
caplog.set_level(logging.CRITICAL, logger="llama_stack.core.server.auth_providers")
|
||||
|
||||
|
||||
class MockResponse:
|
||||
def __init__(self, status_code, json_data):
|
||||
self.status_code = status_code
|
||||
|
|
@ -119,7 +127,7 @@ def test_authenticated_endpoint_with_valid_github_token(mock_client_class, githu
|
|||
|
||||
|
||||
@patch("llama_stack.core.server.auth_providers.httpx.AsyncClient")
|
||||
def test_authenticated_endpoint_with_invalid_github_token(mock_client_class, github_token_client):
|
||||
def test_authenticated_endpoint_with_invalid_github_token(mock_client_class, github_token_client, suppress_auth_errors):
|
||||
"""Test accessing protected endpoint with invalid GitHub token"""
|
||||
# Mock the GitHub API to return 401 Unauthorized
|
||||
mock_client = AsyncMock()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue