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]

tests fix use correct import responses

Ishaan Jaffe03686de5f9a
diff --git a/tests/test_litellm/proxy/client/test_chat.py b/tests/test_litellm/proxy/client/test_chat.py
index 332edc78575..868d9287692 100644
--- a/tests/test_litellm/proxy/client/test_chat.py
+++ b/tests/test_litellm/proxy/client/test_chat.py
@@ -3,6 +3,7 @@ import sys
import pytest
import requests
+import responses
sys.path.insert(
0, os.path.abspath("../../..")
@@ -125,7 +126,8 @@ def test_completions_all_parameters(client, sample_messages):
}
-def test_completions_mock_response(client, sample_messages, requests_mock):
+def test_completions_mock_response(client, sample_messages):
"""Test completions with a mocked successful response"""
mock_response = {
"id": "chatcmpl-123",
@@ -146,7 +148,12 @@ def test_completions_mock_response(client, sample_messages, requests_mock):
}
# Mock the POST request
- requests_mock.post(f"{client._base_url}/chat/completions", json=mock_response)
+ responses.add(
+ responses.POST,
+ f"{client._base_url}/chat/completions",
+ json=mock_response,
+ status=200,
+ )
response = client.completions(model="gpt-4", messages=sample_messages)
@@ -157,12 +164,14 @@ def test_completions_mock_response(client, sample_messages, requests_mock):
)
-def test_completions_unauthorized_error(client, sample_messages, requests_mock):
+def test_completions_unauthorized_error(client, sample_messages):
"""Test that completions raises UnauthorizedError for 401 responses"""
# Mock a 401 response
- requests_mock.post(
+ responses.add(
+ responses.POST,
f"{client._base_url}/chat/completions",
- status_code=401,
+ status=401,
json={"error": "Unauthorized"},
)
@@ -170,12 +179,14 @@ def test_completions_unauthorized_error(client, sample_messages, requests_mock):
client.completions(model="gpt-4", messages=sample_messages)
-def test_completions_other_errors(client, sample_messages, requests_mock):
+def test_completions_other_errors(client, sample_messages):
"""Test that completions raises HTTPError for other error responses"""
# Mock a 500 response
- requests_mock.post(
+ responses.add(
+ responses.POST,
f"{client._base_url}/chat/completions",
- status_code=500,
+ status=500,
json={"error": "Internal Server Error"},
)
diff --git a/tests/test_litellm/proxy/client/test_credentials.py b/tests/test_litellm/proxy/client/test_credentials.py
index a83e1cf0cde..a6bfb287754 100644
--- a/tests/test_litellm/proxy/client/test_credentials.py
+++ b/tests/test_litellm/proxy/client/test_credentials.py
@@ -3,6 +3,7 @@ import sys
import pytest
import requests
+import responses
sys.path.insert(
0, os.path.abspath("../../..")