From 397c0028315a059d3e9733914029c07fa387788c Mon Sep 17 00:00:00 2001 From: jav1er8 <93607250+jav1er8@users.noreply.github.com> Date: Wed, 9 Sep 2026 14:04:31 -0400 Subject: [PATCH] test(pricing): clear the resolver cache after the patched registry assertions The resolver's lru_cache is process-wide, so the mock-derived entries survived the patch and a later test resolving the same name could have read them instead of the real registry. Wrap the patched assertions in try/finally and clear the cache on the way out. Addresses review feedback on #1289. --- tests/test_pricing.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/test_pricing.py b/tests/test_pricing.py index c97736789..f90bd60ca 100644 --- a/tests/test_pricing.py +++ b/tests/test_pricing.py @@ -40,13 +40,18 @@ def test_prefers_native_provider_route_over_aggregators() -> None: "output_cost_per_token": 6e-06, }, } - with patch.object(litellm, "model_cost", model_cost): - assert resolve_litellm_model("grok-4.5") == "xai/grok-4.5" + try: + with patch.object(litellm, "model_cost", model_cost): + assert resolve_litellm_model("grok-4.5") == "xai/grok-4.5" - # An explicitly aggregator-qualified name still resolves to that aggregator. - resolve_litellm_model.cache_clear() - with patch.object(litellm, "model_cost", model_cost): - assert resolve_litellm_model("x-ai/grok-4.5") == "openrouter/x-ai/grok-4.5" + # An explicitly aggregator-qualified name still resolves to that aggregator. + resolve_litellm_model.cache_clear() + with patch.object(litellm, "model_cost", model_cost): + assert resolve_litellm_model("x-ai/grok-4.5") == "openrouter/x-ai/grok-4.5" + finally: + # The resolver cache is process-wide: drop the mock-derived entries so a + # later test cannot read them instead of consulting the real registry. + resolve_litellm_model.cache_clear() def test_resolver_returns_none_for_unresolvable_model() -> None: