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 fixes

Ishaan Jafferd8e0c43a21e6
diff --git a/tests/test_litellm/test_main.py b/tests/test_litellm/test_main.py
index d900a51279e..d1185c72a29 100644
--- a/tests/test_litellm/test_main.py
+++ b/tests/test_litellm/test_main.py
@@ -477,6 +477,7 @@ async def test_openai_env_base(
respx_mock: respx.MockRouter, env_base, openai_api_response, monkeypatch
):
"This tests OpenAI env variables are honored, including legacy OPENAI_API_BASE"
+ # Ensure aiohttp transport is disabled to use httpx which respx can mock
litellm.disable_aiohttp_transport = True
expected_base_url = "http://localhost:12345/v1"
@@ -488,8 +489,8 @@ async def test_openai_env_base(
model = "gpt-4o"
messages = [{"role": "user", "content": "Hello, how are you?"}]
- # Ensure respx_mock is properly configured - use correct respx API
- respx_mock.post(
+ # Configure respx mock to intercept the request
+ mock_route = respx_mock.post(
url__regex=r"http://localhost:12345/v1/chat/completions.*"
).mock(return_value=httpx.Response(
status_code=200,
@@ -512,10 +513,17 @@ async def test_openai_env_base(
}
))
- response = await litellm.acompletion(model=model, messages=messages)
-
- # verify we had a response
- assert response.choices[0].message.content == "Hello from mocked response!"
+ try:
+ response = await litellm.acompletion(model=model, messages=messages)
+
+ # verify we had a response
+ assert response.choices[0].message.content == "Hello from mocked response!"
+
+ # Verify the mock was called
+ assert mock_route.called, "Mock route was not called - request may have bypassed respx"
+ finally:
+ # Clean up to avoid affecting other tests
+ litellm.disable_aiohttp_transport = False
def build_database_url(username, password, host, dbname):
diff --git a/tests/test_litellm/test_video_generation.py b/tests/test_litellm/test_video_generation.py
index 73bfa71d20b..cfc1535052c 100644
--- a/tests/test_litellm/test_video_generation.py
+++ b/tests/test_litellm/test_video_generation.py
@@ -204,7 +204,7 @@ class TestVideoGeneration:
"""Test video generation cost calculation."""
import json
import os
-
+
# Try to load the local model cost map, skip if not found
cost_map_path = "model_prices_and_context_window.json"
if not os.path.exists(cost_map_path):
@@ -294,39 +294,47 @@ class TestVideoGeneration:
with patch.object(config, 'transform_video_create_request') as mock_transform:
mock_transform.return_value = ({"model": "sora-2", "prompt": "test"}, [], "https://api.openai.com/v1/videos")
- mock_response = MagicMock()
- mock_response.json.return_value = {
- "id": "video_123",
- "object": "video",
- "status": "queued",
- "created_at": 1712697600,
- "model": "sora-2"
- }
- mock_response.status_code = 200
-
- mock_client = MagicMock()
- mock_client.post.return_value = mock_response
-
- with patch(
- "litellm.llms.custom_httpx.llm_http_handler._get_httpx_client",
- return_value=mock_client,
- ):
- handler.video_generation_handler(
- model="sora-2",
- prompt="test prompt",
- video_generation_provider_config=config,
- video_generation_optional_request_params={},
- custom_llm_provider="openai",
- litellm_params={"api_key": "deployment-api-key", "api_base": "https://api.openai.com/v1"},
- logging_obj=MagicMock(),
- timeout=5.0,
- api_key=None, # Function parameter is None
- _is_async=False,
- )
-
- # Verify validate_environment was called with api_key from litellm_params
- mock_validate.assert_called_once()
- call_args = mock_validate.call_args
+ # Mock the transform_video_create_response to avoid needing a real response
+ with patch.object(config, 'transform_video_create_response') as mock_transform_response:
+ mock_video_object = MagicMock()
+ mock_video_object.id = "video_123"
+ mock_video_object.object = "video"
+ mock_video_object.status = "queued"
+ mock_transform_response.return_value = mock_video_object
+
+ mock_response = MagicMock()
+ mock_response.json.return_value = {
+ "id": "video_123",
+ "object": "video",
+ "status": "queued",
+ "created_at": 1712697600,
+ "model": "sora-2"
+ }
+ mock_response.status_code = 200
+
+ mock_client = MagicMock()
+ mock_client.post.return_value = mock_response
+
+ with patch(
+ "litellm.llms.custom_httpx.llm_http_handler._get_httpx_client",
+ return_value=mock_client,
+ ):
+ result = handler.video_generation_handler(
+ model="sora-2",
+ prompt="test prompt",
+ video_generation_provider_config=config,
+ video_generation_optional_request_params={},
+ custom_llm_provider="openai",
+ litellm_params={"api_key": "deployment-api-key", "api_base": "https://api.openai.com/v1"},
+ logging_obj=MagicMock(),
+ timeout=5.0,
+ api_key=None, # Function parameter is None
+ _is_async=False,
+ )
+
+ # Verify validate_environment was called with api_key from litellm_params
+ mock_validate.assert_called_once()
+ call_args = mock_validate.call_args
assert call_args.kwargs["api_key"] == "deployment-api-key"
def test_video_generation_url_generation(self):
@@ -824,7 +832,7 @@ def test_video_content_handler_uses_get_for_openai():
def test_video_content_respects_api_base_and_api_key_from_kwargs():
"""Test that video_content respects api_base and api_key from kwargs (simulating database entry)."""
from litellm.videos.main import video_content
-
+
# Mock the handler to capture litellm_params
captured_litellm_params = None
@@ -916,10 +924,16 @@ class TestVideoEndpointsProxyLitellmParams:
"""Create a test client with a proxy config that includes Vertex AI model with litellm_params."""
import asyncio
import tempfile
+
import yaml
from fastapi import FastAPI
from fastapi.testclient import TestClient
- from litellm.proxy.proxy_server import cleanup_router_config_variables, router, initialize
+
+ from litellm.proxy.proxy_server import (
+ cleanup_router_config_variables,
+ initialize,
+ router,
+ )
from litellm.proxy.video_endpoints.endpoints import router as video_router
# Clean up any existing router config