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.
This commit is contained in:
jav1er8 2026-09-09 14:04:31 -04:00
parent e0623b5096
commit 397c002831

View file

@ -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: