From 0c87bf5de9aa87d176c2fec3af078455261e5f6d Mon Sep 17 00:00:00 2001 From: Yuneng Jiang Date: Wed, 26 Aug 2026 00:32:25 -0700 Subject: [PATCH] test(cost-estimate): keep the new tests inside the test-quality budgets Two of the new lines tripped the ratcheting gate. TQ005 flagged restoring litellm.model_cost by assignment. Dropped the save/restore pair for monkeypatch.setitem, which adds the one model the test needs and takes it back out at teardown, so the module global is never reassigned. TQ008 flagged patching litellm.proxy.proxy_server.llm_router. The endpoint imports the router from that module inside the function body, so there is no seam to inject through without changing the endpoint. Suppressed with the reason already used elsewhere in the suite for the same module global, on the single helper the new tests share. --- .../test_cost_tracking_settings.py | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/tests/test_litellm/proxy/management_endpoints/test_cost_tracking_settings.py b/tests/test_litellm/proxy/management_endpoints/test_cost_tracking_settings.py index 2b2476d3c99..ec62cc47018 100644 --- a/tests/test_litellm/proxy/management_endpoints/test_cost_tracking_settings.py +++ b/tests/test_litellm/proxy/management_endpoints/test_cost_tracking_settings.py @@ -815,7 +815,9 @@ async def _estimate(mock_router: MagicMock | None, model: str = AN_ALIAS, **over output_tokens=OUTPUT_TOKENS, **overrides, ) - with patch("litellm.proxy.proxy_server.llm_router", mock_router): + with patch( # test-quality-ok: proxy_server module global is the endpoint's only injection point + "litellm.proxy.proxy_server.llm_router", mock_router + ): return await estimate_cost(request=request, user_api_key_dict=MagicMock()) @@ -837,22 +839,19 @@ class TestEstimateCostPartiallyPricedDeployments: assert response.cost_per_request == pytest.approx(0.001) @pytest.mark.asyncio - async def test_a_model_priced_only_by_the_cost_map_reports_that_price_and_provider(self): - saved_model_cost = dict(litellm.model_cost) - litellm.register_model( + async def test_a_model_priced_only_by_the_cost_map_reports_that_price_and_provider(self, monkeypatch): + monkeypatch.setitem( + litellm.model_cost, + A_MAPPED_MODEL, { - A_MAPPED_MODEL: { - "input_cost_per_token": 0.000005, - "output_cost_per_token": 0.000006, - "litellm_provider": "openai", - "mode": "chat", - } - } + "input_cost_per_token": 0.000005, + "output_cost_per_token": 0.000006, + "litellm_provider": "openai", + "mode": "chat", + }, ) - try: - response = await _estimate(None, model=A_MAPPED_MODEL) - finally: - litellm.model_cost = saved_model_cost + + response = await _estimate(None, model=A_MAPPED_MODEL) assert response.input_cost_per_token == pytest.approx(0.000005) assert response.output_cost_per_token == pytest.approx(0.000006)