Merge pull request #22720 from BerriAI/fix/proxy-utils-mock-request-state

fix: use real State in mock_request for proxy_utils tests
This commit is contained in:
Julio Quinteros Pro 2026-03-03 20:10:53 -03:00 committed by GitHub
commit d9a349f7d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8,6 +8,7 @@ from unittest.mock import Mock
import pytest
from fastapi import Request
from starlette.datastructures import State
from litellm.proxy.utils import _get_docs_url, _get_redoc_url
@ -32,6 +33,7 @@ def mock_request(monkeypatch):
mock_request = Mock(spec=Request)
mock_request.query_params = {} # Set mock query_params to an empty dictionary
mock_request.headers = {"traceparent": "test_traceparent"}
mock_request.state = State() # Real State so _safe_get_request_headers caching works
monkeypatch.setattr(
"litellm.proxy.litellm_pre_call_utils.add_litellm_data_to_request", mock_request
)
@ -810,6 +812,7 @@ async def test_add_litellm_data_to_request_duplicate_tags(
mock_request.url.path = "/chat/completions"
mock_request.query_params = {}
mock_request.headers = {}
mock_request.state = State()
# Setup key with tags in metadata
user_api_key_dict = UserAPIKeyAuth(