From d80daa4827b1e61e795a07ad5052bc58ff311b03 Mon Sep 17 00:00:00 2001 From: Zuraiz Anjum Date: Sun, 4 Oct 2026 16:17:08 +0500 Subject: [PATCH] test(streaming): use a fixed start time and check the estimated cost --- tests/unit/litellm_core_utils/test_streaming_handler.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/unit/litellm_core_utils/test_streaming_handler.py b/tests/unit/litellm_core_utils/test_streaming_handler.py index d2cf7104435..54ea61e0155 100644 --- a/tests/unit/litellm_core_utils/test_streaming_handler.py +++ b/tests/unit/litellm_core_utils/test_streaming_handler.py @@ -1,3 +1,4 @@ +import datetime import json import time from unittest.mock import AsyncMock, MagicMock, Mock, patch @@ -2378,7 +2379,7 @@ async def test_stream_without_provider_usage_falls_back_to_the_token_estimate( messages=messages, stream=True, call_type="completion", - start_time=time.time(), + start_time=datetime.datetime(2025, 3, 3, 21, 38, 10), litellm_call_id="no-usage-call", function_id="no-usage-fn", ), @@ -2397,6 +2398,10 @@ async def test_stream_without_provider_usage_falls_back_to_the_token_estimate( hidden_usage: Final = collected[-1]._hidden_params["usage"] assert (hidden_usage.prompt_tokens, hidden_usage.completion_tokens) == expected + rates: Final = litellm.model_cost[model] + spend: Final = expected[0] * rates["input_cost_per_token"] + expected[1] * rates["output_cost_per_token"] + assert litellm.completion_cost(completion_response=assembled) == pytest.approx(spend) + @pytest.mark.asyncio async def test_custom_stream_wrapper_aclose():