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]

fix(test): correct async mock for video generation logging test

Julio Quinteros Pro8ea0c93d67fc
diff --git a/tests/test_litellm/test_video_generation.py b/tests/test_litellm/test_video_generation.py
index d4150c349f4..0d90b5188f1 100644
--- a/tests/test_litellm/test_video_generation.py
+++ b/tests/test_litellm/test_video_generation.py
@@ -731,50 +731,58 @@ class TestVideoLogging:
@pytest.mark.asyncio
async def test_video_generation_logging(self):
- """Test that video generation creates proper logging payload with cost tracking."""
+ """Test that video generation creates proper logging payload with cost tracking.
+
+ Note: Uses AsyncMock with side_effect pattern for reliable parallel execution.
+ """
+ import litellm.videos.main as videos_main
+
custom_logger = self.TestVideoLogger()
litellm.logging_callback_manager._reset_all_callbacks()
litellm.callbacks = [custom_logger]
-
+
# Mock video generation response
mock_response = VideoObject(
id="video_test_123",
- object="video",
+ object="video",
status="queued",
created_at=1712697600,
model="sora-2",
size="720x1280",
seconds="8"
)
-
- with patch('litellm.videos.main.base_llm_http_handler') as mock_handler:
- mock_handler.video_generation_handler.return_value = mock_response
-
+
+ # Create async mock function to return the mock_response
+ async def mock_async_handler(*args, **kwargs):
+ return mock_response
+
+ # Patch the async_video_generation_handler method on base_llm_http_handler
+ with patch.object(videos_main.base_llm_http_handler, 'async_video_generation_handler', side_effect=mock_async_handler):
response = await litellm.avideo_generation(
prompt="A cat running in a garden",
model="sora-2",
seconds="8",
size="720x1280"
)
-
+
await asyncio.sleep(1) # Allow logging to complete
-
+
# Verify logging payload was created
assert custom_logger.standard_logging_payload is not None
-
+
payload = custom_logger.standard_logging_payload
-
+
# Verify basic logging fields
assert payload["call_type"] == "avideo_generation"
assert payload["status"] == "success"
assert payload["model"] == "sora-2"
assert payload["custom_llm_provider"] == "openai"
-
+
# Verify response object is recognized for logging
assert payload["response"] is not None
assert payload["response"]["id"] == "video_test_123"
assert payload["response"]["object"] == "video"
-
+
# Verify cost tracking is present (may be 0 in test environment)
assert payload["response_cost"] is not None
# Note: Cost calculation may not work in test environment due to mocking