test(bedrock): restore litellm.model_cost via monkeypatch in Claude 5 structured-output regression test

Fixes the TQ005 test-quality gate failure on the PR: the regression test
mutated the litellm.model_cost process-wide global with manual
save/restore; monkeypatch.setattr restores it at teardown instead.
This commit is contained in:
Kaustubh Anil Jain 2026-10-22 08:49:32 +05:30
parent 87450f2364
commit 01ddfca9a9

View file

@ -4867,47 +4867,38 @@ def test_translate_response_format_native_output_config_claude_5_family(monkeypa
Regression test for: https://github.com/BerriAI/litellm/issues/47687
"""
old_env = os.environ.get("LITELLM_LOCAL_MODEL_COST_MAP")
old_cost = litellm.model_cost
monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True")
litellm.model_cost = litellm.get_model_cost_map(url="")
try:
config = AmazonConverseConfig()
response_format = {
"type": "json_schema",
"json_schema": {
"name": "ScoreResult",
"schema": {
"type": "object",
"properties": {"score": {"type": "number"}},
"required": ["score"],
},
monkeypatch.setattr(litellm, "model_cost", litellm.get_model_cost_map(url=""))
config = AmazonConverseConfig()
response_format = {
"type": "json_schema",
"json_schema": {
"name": "ScoreResult",
"schema": {
"type": "object",
"properties": {"score": {"type": "number"}},
"required": ["score"],
},
}
for model in (
"us.anthropic.claude-opus-5-5",
"us.anthropic.claude-sonnet-5-5",
"us.anthropic.claude-haiku-5-5",
"anthropic.claude-opus-5",
"anthropic.claude-sonnet-5",
):
optional_params: dict = {}
result = config._translate_response_format_param(
value=response_format,
model=model,
optional_params=optional_params,
non_default_params={"response_format": response_format},
is_thinking_enabled=False,
)
assert "outputConfig" in result, f"{model}: json_schema should route to native outputConfig without thinking"
assert "tools" not in result, f"{model}: json tool path must not be used for Claude 5 family"
assert "tool_choice" not in result
finally:
litellm.model_cost = old_cost
if old_env is None:
os.environ.pop("LITELLM_LOCAL_MODEL_COST_MAP", None)
else:
monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", old_env)
},
}
for model in (
"us.anthropic.claude-opus-5-5",
"us.anthropic.claude-sonnet-5-5",
"us.anthropic.claude-haiku-5-5",
"anthropic.claude-opus-5",
"anthropic.claude-sonnet-5",
):
optional_params: dict = {}
result = config._translate_response_format_param(
value=response_format,
model=model,
optional_params=optional_params,
non_default_params={"response_format": response_format},
is_thinking_enabled=False,
)
assert "outputConfig" in result, f"{model}: json_schema should route to native outputConfig without thinking"
assert "tools" not in result, f"{model}: json tool path must not be used for Claude 5 family"
assert "tool_choice" not in result
CAPITAL_RESPONSE_FORMAT: Final = {