From 09dcd381d78e628b7e670b6335ab60c06bf78b3a Mon Sep 17 00:00:00 2001 From: Alexsander Hamir Date: Sat, 6 Dec 2025 09:41:09 -0800 Subject: [PATCH] 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 --- tests/local_testing/test_caching.py | 34 ++++++++++++++++------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/tests/local_testing/test_caching.py b/tests/local_testing/test_caching.py index 2b2c9853db..7fb57cef9e 100644 --- a/tests/local_testing/test_caching.py +++ b/tests/local_testing/test_caching.py @@ -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