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

The test was failing with AuthenticationError because the mock wasn't
intercepting the actual HTTP handler calls. This caused real API calls
with no API key, resulting in 401 errors.

Root cause: The test was patching the wrong target using string path
'litellm.videos.main.base_llm_http_handler' instead of using patch.object
on the actual handler instance. Additionally, it was mocking the sync
method instead of async_video_generation_handler.

Solution: Use patch.object with side_effect pattern on the correct
async handler method, following the same pattern used in
test_video_generation_async().

Fixes test failure in PR #21277 when running with --dist=loadscope.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Julio Quinteros Pro
2026-02-15 20:40:43 -03:00
co-authored by Claude Sonnet 4.5
parent b0f2b4bb2d
commit 8ea0c93d67
+21 -13
View File
@@ -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