From 8ea0c93d67fce29dec4d205cbd06523ff34d9fc9 Mon Sep 17 00:00:00 2001 From: Julio Quinteros Pro Date: Sun, 15 Feb 2026 20:40:43 -0300 Subject: [PATCH 1/2] 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 --- tests/test_litellm/test_video_generation.py | 34 +++++++++++++-------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/tests/test_litellm/test_video_generation.py b/tests/test_litellm/test_video_generation.py index d4150c349f..0d90b5188f 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 From f2b6c38c8672801af4903ad6c4c66debbbb36cbd Mon Sep 17 00:00:00 2001 From: Julio Quinteros Pro Date: Sun, 15 Feb 2026 21:15:52 -0300 Subject: [PATCH 2/2] Remove redundant import inside test method The module litellm.videos.main is already imported at the top of the file (line 21), so the import inside the test method is redundant. Addresses Greptile feedback (minor style issue). Co-Authored-By: Claude Sonnet 4.5 --- tests/test_litellm/test_video_generation.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_litellm/test_video_generation.py b/tests/test_litellm/test_video_generation.py index 0d90b5188f..121bf1a1f0 100644 --- a/tests/test_litellm/test_video_generation.py +++ b/tests/test_litellm/test_video_generation.py @@ -735,8 +735,6 @@ class TestVideoLogging: 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]