From 45fa78470df87ef0b8e4f7f20643a135aa6ffc6a Mon Sep 17 00:00:00 2001 From: ryan-crabbe-berri Date: Tue, 1 Sep 2026 15:14:56 -0700 Subject: [PATCH] test(router): inject the upstream client instead of mutating litellm.aclient_session The text-completion wire test set litellm.aclient_session, which the test-quality gate (TQ005) flags as a process-wide global write. Pass an AsyncOpenAI client through the router's client kwarg instead, so the test owns its transport and needs no cache flush or global restore. Claude-Session: https://claude.ai/code/session_01XKkTFa6g7Rmd6vtHL91GMn --- tests/test_litellm/test_router_order_fallback.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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