style(tests): swap the model_cost save/restore for monkeypatch.setattr

The test-quality gate (TQ005) counts direct litellm.<attr> = ... module-
global mutations against a merge-base ceiling; monkeypatch.setattr
restores the attribute at teardown without tripping the rule.
This commit is contained in:
OrangerXu 2026-10-15 14:47:41 +08:00
parent f594efe634
commit a0bfdc85d3

View file

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