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 flaky encrypted_content_affinity tests: clear HTTP client cache, disable retries

yuneng-jiang67e905f0d0cc
diff --git a/tests/test_litellm/router_utils/pre_call_checks/test_encrypted_content_affinity_check.py b/tests/test_litellm/router_utils/pre_call_checks/test_encrypted_content_affinity_check.py
index 6e845e9d050..5f629f1fb32 100644
--- a/tests/test_litellm/router_utils/pre_call_checks/test_encrypted_content_affinity_check.py
+++ b/tests/test_litellm/router_utils/pre_call_checks/test_encrypted_content_affinity_check.py
@@ -28,6 +28,22 @@ import json
import litellm
from litellm.responses.utils import ResponsesAPIRequestUtils
+
[email protected](autouse=True)
+def _clear_http_client_cache():
+ """
+ Clear the shared HTTP client cache before each test so that cached clients
+ from other tests (running in the same pytest-xdist worker) do not bypass
+ class-level mocks on AsyncHTTPHandler.post.
+ """
+ cache = getattr(litellm, "in_memory_llm_clients_cache", None)
+ if cache is not None:
+ cache.flush_cache()
+ yield
+ cache = getattr(litellm, "in_memory_llm_clients_cache", None)
+ if cache is not None:
+ cache.flush_cache()
+
# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
@@ -301,6 +317,7 @@ async def test_encrypted_content_affinity_tracks_and_routes():
},
],
optional_pre_call_checks=["encrypted_content_affinity"],
+ num_retries=0,
)
selected_deployments = []
@@ -376,6 +393,7 @@ async def test_encrypted_content_affinity_no_effect_on_chat_completions():
},
],
optional_pre_call_checks=["encrypted_content_affinity"],
+ num_retries=0,
)
response1 = await router.acompletion(
@@ -435,6 +453,7 @@ async def test_encrypted_content_affinity_bypasses_rpm_limits():
],
optional_pre_call_checks=["encrypted_content_affinity"],
routing_strategy="usage-based-routing-v2",
+ num_retries=0,
)
selected_deployments = []
@@ -527,6 +546,7 @@ async def test_encrypted_content_affinity_no_match_normal_routing():
},
],
optional_pre_call_checks=["encrypted_content_affinity"],
+ num_retries=0,
)
with patch(
@@ -588,6 +608,7 @@ async def test_encrypted_content_affinity_with_wrapped_content_no_id():
},
],
optional_pre_call_checks=["encrypted_content_affinity"],
+ num_retries=0,
)
selected_deployments = []