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]

test(router): inject the upstream client instead of mutating litellm.aclient_session

ryan-crabbe-berri45fa78470df8
diff --git a/tests/test_litellm/test_router_order_fallback.py b/tests/test_litellm/test_router_order_fallback.py
index 8b9075f845c..fde870e5abe 100644
--- a/tests/test_litellm/test_router_order_fallback.py
+++ b/tests/test_litellm/test_router_order_fallback.py
@@ -11,6 +11,7 @@ from typing import Final, Optional
import httpx
import pytest
+from openai import AsyncOpenAI
import litellm
from litellm import Router
@@ -600,9 +601,11 @@ async def test_text_completion_order_fallback_hop_does_not_send_target_order_ups
},
)
- session: Final = httpx.AsyncClient(transport=httpx.MockTransport(_upstream))
- litellm.in_memory_llm_clients_cache.flush_cache()
- litellm.aclient_session = session
+ upstream_client: Final = AsyncOpenAI(
+ api_key="key",
+ base_url="http://upstream.test",
+ http_client=httpx.AsyncClient(transport=httpx.MockTransport(_upstream)),
+ )
router = Router(
model_list=[
{
@@ -629,11 +632,9 @@ async def test_text_completion_order_fallback_hop_does_not_send_target_order_ups
num_retries=0,
)
try:
- response = await router.atext_completion(model="test-model", prompt="hi")
+ response = await router.atext_completion(model="test-model", prompt="hi", client=upstream_client)
finally:
- litellm.aclient_session = None
- litellm.in_memory_llm_clients_cache.flush_cache()
- await session.aclose()
+ await upstream_client.close()
assert response._hidden_params["model_id"] == "2"
assert upstream_bodies