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 error

0x57518dd04c4eeeac
diff --git a/tests/test_litellm/test_main.py b/tests/test_litellm/test_main.py
index 4b79486bb50..954597dda25 100644
--- a/tests/test_litellm/test_main.py
+++ b/tests/test_litellm/test_main.py
@@ -1128,38 +1128,31 @@ def test_anthropic_disable_url_suffix_env_var():
from unittest.mock import patch, MagicMock
import os
from litellm import completion
- from litellm.llms.anthropic.chat.handler import AnthropicLLM
# Test with environment variable disabled (default behavior)
with patch.dict(os.environ, {"ANTHROPIC_API_BASE": "https://api.example.com"}):
- with patch.object(AnthropicLLM, "__init__", return_value=None) as mock_init:
- with patch.object(AnthropicLLM, "completion") as mock_completion:
- mock_completion.return_value = MagicMock()
-
- # Mock the initialization to capture api_base
- actual_api_base = None
- def capture_init(self, **kwargs):
- nonlocal actual_api_base
- actual_api_base = kwargs.get("api_base")
-
- with patch("litellm.main.anthropic_chat_completions") as mock_anthropic:
- def capture_completion(**kwargs):
- nonlocal actual_api_base
- actual_api_base = kwargs.get("api_base")
- return MagicMock()
-
- mock_anthropic.completion = capture_completion
-
- # This should append /v1/messages
- completion(
- model="anthropic/claude-3-sonnet",
- messages=[{"role": "user", "content": "test"}],
- api_key="test-key"
- )
-
- # Verify the api_base has /v1/messages appended
- assert actual_api_base.endswith("/v1/messages")
- assert actual_api_base == "https://api.example.com/v1/messages"
+ actual_api_base = None
+
+ with patch("litellm.main.anthropic_chat_completions") as mock_anthropic:
+ def capture_completion(**kwargs):
+ nonlocal actual_api_base
+ actual_api_base = kwargs.get("api_base")
+ mock_response = MagicMock()
+ mock_response.choices = [MagicMock()]
+ return mock_response
+
+ mock_anthropic.completion = capture_completion
+
+ # This should append /v1/messages
+ completion(
+ model="anthropic/claude-3-sonnet",
+ messages=[{"role": "user", "content": "test"}],
+ api_key="test-key"
+ )
+
+ # Verify the api_base has /v1/messages appended
+ assert actual_api_base.endswith("/v1/messages")
+ assert actual_api_base == "https://api.example.com/v1/messages"
# Test with environment variable enabled
with patch.dict(os.environ, {
@@ -1172,7 +1165,9 @@ def test_anthropic_disable_url_suffix_env_var():
def capture_completion(**kwargs):
nonlocal actual_api_base
actual_api_base = kwargs.get("api_base")
- return MagicMock()
+ mock_response = MagicMock()
+ mock_response.choices = [MagicMock()]
+ return mock_response
mock_anthropic.completion = capture_completion