Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test_no_duplicate_spend_logs

Ishaan Jaffer71ea926f9ad2
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 249374b3078..19b4d5f5242 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, (