fix: mark test_caching_with_reasoning_content as flaky and handle InternalServerError (#17603)

- Add @pytest.mark.flaky(retries=3, delay=1) decorator to handle intermittent Anthropic API failures
- Add error handling to skip test when Anthropic API returns InternalServerError
- Prevents false test failures due to external API 500 errors
This commit is contained in:
Alexsander Hamir
2025-12-06 09:41:09 -08:00
committed by GitHub
parent 497856e1e3
commit 09dcd381d7
+19 -15
View File
@@ -2634,6 +2634,7 @@ def test_redis_caching_multiple_namespaces():
), f"Expected different response ID for no namespace vs namespaced. Got {response_1.id} and {response_4.id}"
@pytest.mark.flaky(retries=3, delay=1)
def test_caching_with_reasoning_content():
"""
Test that reasoning content is cached
@@ -2641,24 +2642,27 @@ def test_caching_with_reasoning_content():
from litellm._uuid import uuid
messages = [{"role": "user", "content": f"what is litellm? {uuid.uuid4()}"}]
litellm.cache = Cache()
try:
messages = [{"role": "user", "content": f"what is litellm? {uuid.uuid4()}"}]
litellm.cache = Cache()
response_1 = completion(
model="anthropic/claude-3-7-sonnet-latest",
messages=messages,
thinking={"type": "enabled", "budget_tokens": 1024},
)
response_1 = completion(
model="anthropic/claude-3-7-sonnet-latest",
messages=messages,
thinking={"type": "enabled", "budget_tokens": 1024},
)
response_2 = completion(
model="anthropic/claude-3-7-sonnet-latest",
messages=messages,
thinking={"type": "enabled", "budget_tokens": 1024},
)
response_2 = completion(
model="anthropic/claude-3-7-sonnet-latest",
messages=messages,
thinking={"type": "enabled", "budget_tokens": 1024},
)
print(f"response 2: {response_2.model_dump_json(indent=4)}")
assert response_2._hidden_params["cache_hit"] == True
assert response_2.choices[0].message.reasoning_content is not None
print(f"response 2: {response_2.model_dump_json(indent=4)}")
assert response_2._hidden_params["cache_hit"] == True
assert response_2.choices[0].message.reasoning_content is not None
except litellm.InternalServerError as e:
pytest.skip(f"Anthropic API returned InternalServerError - {str(e)}")
def test_caching_reasoning_args_miss(): # test in memory cache