From 7e564e108a1d26f9477b8b801b6da63c60d3b346 Mon Sep 17 00:00:00 2001 From: yuneng-berri Date: Sat, 3 Oct 2026 21:00:22 +0000 Subject: [PATCH 1/2] test(utils): mock the prompt-cache token count at its current seam is_prompt_caching_valid_prompt no longer calls token_counter, so the test's patch of litellm.utils.token_counter never fired and call_args was None. Patch the counter the function actually reaches now and keep asserting use_default_image_token_count is True. --- tests/litellm_utils_tests/test_utils.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/litellm_utils_tests/test_utils.py b/tests/litellm_utils_tests/test_utils.py index 92947fbf6fe..6eba5a8e072 100644 --- a/tests/litellm_utils_tests/test_utils.py +++ b/tests/litellm_utils_tests/test_utils.py @@ -1343,12 +1343,15 @@ def test_is_prompt_caching_enabled_error_handling(): def test_is_prompt_caching_enabled_return_default_image_dimensions(): """ - Assert that `is_prompt_caching_valid_prompt` calls token_counter with use_default_image_token_count=True + Assert that `is_prompt_caching_valid_prompt` counts tokens with use_default_image_token_count=True when processing messages containing images IMPORTANT: Ensures Get token counter does not make a GET request to the image url """ - with patch("litellm.utils.token_counter") as mock_token_counter: + mock_token_counter = MagicMock(return_value=False) + with patch( + "litellm.utils._get_messages_reach_token_count", return_value=mock_token_counter + ): litellm.utils.is_prompt_caching_valid_prompt( messages=[ { @@ -1370,7 +1373,7 @@ def test_is_prompt_caching_enabled_return_default_image_dimensions(): model="gpt-4o-mini", ) - # Assert token_counter was called with use_default_image_token_count=True + # Assert the token count was taken with use_default_image_token_count=True args_to_mock_token_counter = mock_token_counter.call_args[1] print("args_to_mock", args_to_mock_token_counter) assert args_to_mock_token_counter["use_default_image_token_count"] is True From 6727f8c38aeed846ca0e04202a40b16974fe1a05 Mon Sep 17 00:00:00 2001 From: yuneng-berri Date: Sat, 3 Oct 2026 21:05:21 +0000 Subject: [PATCH 2/2] test(utils): drop the comment restating the assertion AGENTS.md allows comments only for complex logic, tool input, or a justified TODO. The line repeated the assert below it. --- tests/litellm_utils_tests/test_utils.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/litellm_utils_tests/test_utils.py b/tests/litellm_utils_tests/test_utils.py index 6eba5a8e072..6ee2322844c 100644 --- a/tests/litellm_utils_tests/test_utils.py +++ b/tests/litellm_utils_tests/test_utils.py @@ -1349,9 +1349,7 @@ def test_is_prompt_caching_enabled_return_default_image_dimensions(): IMPORTANT: Ensures Get token counter does not make a GET request to the image url """ mock_token_counter = MagicMock(return_value=False) - with patch( - "litellm.utils._get_messages_reach_token_count", return_value=mock_token_counter - ): + with patch("litellm.utils._get_messages_reach_token_count", return_value=mock_token_counter): litellm.utils.is_prompt_caching_valid_prompt( messages=[ { @@ -1373,7 +1371,6 @@ def test_is_prompt_caching_enabled_return_default_image_dimensions(): model="gpt-4o-mini", ) - # Assert the token count was taken with use_default_image_token_count=True args_to_mock_token_counter = mock_token_counter.call_args[1] print("args_to_mock", args_to_mock_token_counter) assert args_to_mock_token_counter["use_default_image_token_count"] is True