Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix: use real State object in mock_request to fix _safe_get_request_headers

Julio Quinteros Pro740cdc5c20b2
diff --git a/tests/proxy_unit_tests/test_proxy_utils.py b/tests/proxy_unit_tests/test_proxy_utils.py
index f7101085f0f..b2ed4f91037 100644
--- a/tests/proxy_unit_tests/test_proxy_utils.py
+++ b/tests/proxy_unit_tests/test_proxy_utils.py
@@ -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(