From a0bfdc85d3d4d46144c8aaedaca7504271f9f459 Mon Sep 17 00:00:00 2001 From: OrangerXu Date: Thu, 15 Oct 2026 14:47:41 +0800 Subject: [PATCH] style(tests): swap the model_cost save/restore for monkeypatch.setattr The test-quality gate (TQ005) counts direct litellm. = ... module- global mutations against a merge-base ceiling; monkeypatch.setattr restores the attribute at teardown without tripping the rule. --- tests/unit/test_image_cost_data_residency.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/unit/test_image_cost_data_residency.py b/tests/unit/test_image_cost_data_residency.py index 881c425e8ff..f74e2edfee9 100644 --- a/tests/unit/test_image_cost_data_residency.py +++ b/tests/unit/test_image_cost_data_residency.py @@ -22,15 +22,13 @@ from litellm.types.utils import ( @pytest.fixture(autouse=True) def _use_local_model_cost_map(monkeypatch): - original_model_cost = litellm.model_cost monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True") - litellm.model_cost = litellm.get_model_cost_map(url="") + monkeypatch.setattr( + litellm, "model_cost", litellm.get_model_cost_map(url="") + ) + litellm.get_model_info.cache_clear() + yield litellm.get_model_info.cache_clear() - try: - yield - finally: - litellm.model_cost = original_model_cost - litellm.get_model_info.cache_clear() def _usage() -> ImageUsage: