From 71ea926f9ad2a0dda604d25b77832e44c6c0c293 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Sat, 6 Dec 2025 09:55:35 -0800 Subject: [PATCH] test_no_duplicate_spend_logs --- .../responses/test_no_duplicate_spend_logs.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test_litellm/responses/test_no_duplicate_spend_logs.py b/tests/test_litellm/responses/test_no_duplicate_spend_logs.py index 249374b307..19b4d5f524 100644 --- a/tests/test_litellm/responses/test_no_duplicate_spend_logs.py +++ b/tests/test_litellm/responses/test_no_duplicate_spend_logs.py @@ -5,8 +5,10 @@ This test verifies the fix for issue #15740 where kwargs.pop() was removing the logging object before passing kwargs to internal acompletion() calls, causing duplicate spend log entries for non-OpenAI providers. """ -import sys +import asyncio import os +import sys + import pytest sys.path.insert( @@ -26,6 +28,7 @@ def test_logging_object_not_popped(): spend logs for non-OpenAI providers. """ import inspect + from litellm.responses import main as responses_module # Get the source code of the responses function @@ -84,9 +87,11 @@ async def test_no_duplicate_spend_logs(): ) # Wait for async logging to complete using the logging worker's flush method - # This is more reliable than sleep() which can cause race conditions + # Then add a small delay to ensure callbacks finish executing from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER await GLOBAL_LOGGING_WORKER.flush() + # flush() empties the queue but callbacks may still be running + await asyncio.sleep(0.5) # Verify that log_success_event was called exactly once assert spend_logger.log_count == 1, (