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]

Close httpx clients after assertions to prevent resource leaks

Ryan Crabbedce597b806ea
diff --git a/tests/test_litellm/caching/test_llm_client_cache_e2e.py b/tests/test_litellm/caching/test_llm_client_cache_e2e.py
index b1f8be3b484..a7d012d2269 100644
--- a/tests/test_litellm/caching/test_llm_client_cache_e2e.py
+++ b/tests/test_litellm/caching/test_llm_client_cache_e2e.py
@@ -23,9 +23,11 @@ async def test_evicted_client_is_not_closed():
one, then verify the first client's transport is still open."""
client_a = get_async_httpx_client(llm_provider="provider_a")
# This evicts client_a from cache (capacity=1)
- get_async_httpx_client(llm_provider="provider_b")
+ client_b = get_async_httpx_client(llm_provider="provider_b")
assert not client_a.client.is_closed
+ await client_a.client.aclose()
+ await client_b.client.aclose()
@pytest.mark.asyncio
@@ -42,3 +44,4 @@ async def test_expired_client_is_not_closed():
cache.evict_cache()
assert not client.client.is_closed
+ await client.client.aclose()