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: enforce F811 so a duplicate definition cannot silently replace the first

ryan-crabbe-berrie9d40a8f7375
diff --git a/ruff-tests.toml b/ruff-tests.toml
index 60438d355f0..c6522d6b335 100644
--- a/ruff-tests.toml
+++ b/ruff-tests.toml
@@ -26,6 +26,9 @@
# PT014 the same `parametrize` case listed twice. The copy re-runs an assertion that
# already passed and adds no coverage, and it usually marks a case someone meant
# to vary and forgot to edit
+# F811 a name bound twice where the first binding was never used. Mostly a repeated
+# import, but the same rule is what catches a second `def test_x` silently
+# replacing the first, and a local that shadows an import the module still calls
#
# No target-version here on purpose: it resolves from requires-python (>=3.10), so
# 3.11-only builtins like BaseExceptionGroup are correctly flagged in a tree that
@@ -33,4 +36,4 @@
line-length = 120
-lint.select = ["F821", "B011", "B015", "B017", "B018", "PT011", "PT012", "PT014", "PT015", "PLR0133", "PLW0127"]
+lint.select = ["F811", "F821", "B011", "B015", "B017", "B018", "PT011", "PT012", "PT014", "PT015", "PLR0133", "PLW0127"]
diff --git a/tests/audio_tests/test_audio_speech.py b/tests/audio_tests/test_audio_speech.py
index 52a2316a16f..fb9e679699a 100644
--- a/tests/audio_tests/test_audio_speech.py
+++ b/tests/audio_tests/test_audio_speech.py
@@ -12,7 +12,6 @@ from litellm._uuid import uuid
from dotenv import load_dotenv
load_dotenv()
-import os
sys.path.insert(
0, os.path.abspath("../..")
@@ -452,7 +451,7 @@ async def test_azure_ava_tts_with_custom_voice():
Test that when using a custom Azure voice (en-US-AndrewNeural),
the SSML request body contains the selected voice.
"""
- from unittest.mock import AsyncMock, MagicMock, patch
+ from unittest.mock import AsyncMock, patch
import httpx
# Mock response
@@ -497,7 +496,7 @@ async def test_azure_ava_tts_fable_voice_mapping():
Test that when using OpenAI voice 'fable',
it gets mapped to Azure voice 'en-GB-RyanNeural' in the SSML.
"""
- from unittest.mock import AsyncMock, MagicMock, patch
+ from unittest.mock import AsyncMock, patch
import httpx
# Mock response
@@ -544,7 +543,7 @@ async def test_aws_polly_tts_with_native_voice():
Verifies the request is formatted correctly for the Polly API.
"""
import json
- from unittest.mock import MagicMock, patch
+ from unittest.mock import patch
import httpx
# Mock response - Polly returns audio bytes directly
@@ -592,7 +591,7 @@ async def test_aws_polly_tts_with_openai_voice_mapping():
Verifies that OpenAI voices are correctly mapped to Polly voices.
"""
import json
- from unittest.mock import MagicMock, patch
+ from unittest.mock import patch
import httpx
mock_response_content = b"fake_audio_data"
@@ -634,7 +633,7 @@ async def test_aws_polly_tts_with_ssml():
Verifies that SSML is detected and TextType is set correctly.
"""
import json
- from unittest.mock import MagicMock, patch
+ from unittest.mock import patch
import httpx
mock_response_content = b"fake_audio_data"
diff --git a/tests/audio_tests/test_whisper.py b/tests/audio_tests/test_whisper.py
index 76f7117d46c..333d806fe41 100644
--- a/tests/audio_tests/test_whisper.py
+++ b/tests/audio_tests/test_whisper.py
@@ -44,7 +44,6 @@ load_dotenv()
sys.path.insert(
0, os.path.abspath("../")
) # Adds the parent directory to the system path
-import litellm
from litellm import Router
@@ -146,7 +145,6 @@ async def test_whisper_log_pre_call():
from litellm.litellm_core_utils.litellm_logging import Logging
from datetime import datetime
from unittest.mock import patch, MagicMock
- from litellm.integrations.custom_logger import CustomLogger
custom_logger = CustomLogger()
diff --git a/tests/enterprise/conftest.py b/tests/enterprise/conftest.py
index 0365bbbcfa0..f23a5664f83 100644
--- a/tests/enterprise/conftest.py
+++ b/tests/enterprise/conftest.py
@@ -35,7 +35,6 @@ def setup_and_teardown():
0, os.path.abspath("../..")
) # Adds the project directory to the system path
- import litellm
from litellm import Router
importlib.reload(litellm)
diff --git a/tests/enterprise/litellm_enterprise/integrations/test_prometheus.py b/tests/enterprise/litellm_enterprise/integrations/test_prometheus.py
index bdf73b6ab03..6c4a008c823 100644
--- a/tests/enterprise/litellm_enterprise/integrations/test_prometheus.py
+++ b/tests/enterprise/litellm_enterprise/integrations/test_prometheus.py
@@ -755,7 +755,6 @@ class MockHistogram:
@pytest.fixture
def mock_prometheus_logger():
"""Create a PrometheusLogger with mocked metrics to test increment logic"""
- from unittest.mock import patch
collectors = list(REGISTRY._collector_to_names.keys())
for collector in collectors:
@@ -1186,7 +1185,7 @@ async def test_langfuse_callback_failure_metric(prometheus_logger):
This test verifies that when Langfuse logging fails, the
litellm_callback_logging_failures_metric is incremented with callback_name="langfuse".
"""
- from unittest.mock import MagicMock, patch
+ from unittest.mock import MagicMock
from litellm.integrations.langfuse.langfuse_prompt_management import (
LangfusePromptManagement,
@@ -1242,7 +1241,7 @@ async def test_langfuse_otel_callback_failure_metric(prometheus_logger):
This test verifies that when Langfuse OTEL logging fails, the
litellm_callback_logging_failures_metric is incremented with callback_name="langfuse_otel".
"""
- from unittest.mock import MagicMock, patch
+ from unittest.mock import MagicMock
from litellm.integrations.langfuse.langfuse_otel import LangfuseOtelLogger
diff --git a/tests/enterprise/litellm_enterprise/integrations/test_prometheus_unit_tests.py b/tests/enterprise/litellm_enterprise/integrations/test_prometheus_unit_tests.py
index 55c4cbae821..f5c39fb86ae 100644
--- a/tests/enterprise/litellm_enterprise/integrations/test_prometheus_unit_tests.py
+++ b/tests/enterprise/litellm_enterprise/integrations/test_prometheus_unit_tests.py
@@ -19,7 +19,7 @@ import os
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system-path
-from unittest.mock import MagicMock, patch
+from unittest.mock import MagicMock
import pytest
diff --git a/tests/guardrails_tests/test_custom_guardrail.py b/tests/guardrails_tests/test_custom_guardrail.py
index af1270756f2..9d7efeecdca 100644
--- a/tests/guardrails_tests/test_custom_guardrail.py
+++ b/tests/guardrails_tests/test_custom_guardrail.py
@@ -26,10 +26,8 @@ from litellm.integrations.custom_guardrail import CustomGuardrail
from typing import Any, Dict, List, Literal, Optional, Union
-import litellm
from litellm._logging import verbose_proxy_logger
from litellm.caching.caching import DualCache
-from litellm.integrations.custom_guardrail import CustomGuardrail
from litellm.proxy._types import UserAPIKeyAuth
from litellm.proxy.guardrails.guardrail_helpers import should_proceed_based_on_metadata
from litellm.types.guardrails import GuardrailEventHooks
diff --git a/tests/litellm_utils_tests/conftest.py b/tests/litellm_utils_tests/conftest.py
index 68c281a045f..39ea4299f35 100644
--- a/tests/litellm_utils_tests/conftest.py
+++ b/tests/litellm_utils_tests/conftest.py
@@ -42,7 +42,6 @@ def setup_and_teardown():
0, os.path.abspath("../..")
) # Adds the project directory to the system path
- import litellm
importlib.reload(litellm)
diff --git a/tests/litellm_utils_tests/test_aws_secret_manager.py b/tests/litellm_utils_tests/test_aws_secret_manager.py
index 46e8d004534..787e75eb17b 100644
--- a/tests/litellm_utils_tests/test_aws_secret_manager.py
+++ b/tests/litellm_utils_tests/test_aws_secret_manager.py
@@ -13,8 +13,6 @@ import litellm.types.utils
load_dotenv()
import io
-import sys
-import os
# Ensure the project root is in the Python path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../..")))
diff --git a/tests/litellm_utils_tests/test_hashicorp.py b/tests/litellm_utils_tests/test_hashicorp.py
index fa39a045227..1d98debef2c 100644
--- a/tests/litellm_utils_tests/test_hashicorp.py
+++ b/tests/litellm_utils_tests/test_hashicorp.py
@@ -4,7 +4,6 @@ import pytest
from dotenv import load_dotenv
load_dotenv()
-import os
import httpx
sys.path.insert(
diff --git a/tests/litellm_utils_tests/test_health_check.py b/tests/litellm_utils_tests/test_health_check.py
index 654fde90f26..9a17aaeea87 100644
--- a/tests/litellm_utils_tests/test_health_check.py
+++ b/tests/litellm_utils_tests/test_health_check.py
@@ -785,19 +785,19 @@ async def test_image_generation_health_check_prompt(monkeypatch):
# Default prompt is used when env var is unset
monkeypatch.delenv("DEFAULT_HEALTH_CHECK_PROMPT", raising=False)
- litellm_constants, health_check = reload_modules()
- health_check_calls = await run_health_check(health_check)
+ reloaded_constants, reloaded_health_check = reload_modules()
+ health_check_calls = await run_health_check(reloaded_health_check)
assert len(health_check_calls) == 1
assert (
- health_check_calls[0]["prompt"] == litellm_constants.DEFAULT_HEALTH_CHECK_PROMPT
+ health_check_calls[0]["prompt"] == reloaded_constants.DEFAULT_HEALTH_CHECK_PROMPT
)
# Environment override should change the prompt without code changes
override_prompt = "environment override prompt"
monkeypatch.setenv("DEFAULT_HEALTH_CHECK_PROMPT", override_prompt)
- litellm_constants, health_check = reload_modules()
- health_check_calls = await run_health_check(health_check)
+ _, reloaded_health_check = reload_modules()
+ health_check_calls = await run_health_check(reloaded_health_check)
assert len(health_check_calls) == 1
assert health_check_calls[0]["prompt"] == override_prompt
diff --git a/tests/litellm_utils_tests/test_logging_callback_manager.py b/tests/litellm_utils_tests/test_logging_callback_manager.py
index d9bfca425e4..517ba6befd7 100644
--- a/tests/litellm_utils_tests/test_logging_callback_manager.py
+++ b/tests/litellm_utils_tests/test_logging_callback_manager.py
@@ -243,7 +243,7 @@ async def test_slack_alerting_callback_registration(callback_manager):
from litellm.caching.caching import DualCache
from litellm.proxy.utils import ProxyLogging
from litellm.integrations.SlackAlerting.slack_alerting import SlackAlerting
- from unittest.mock import AsyncMock, patch
+ from unittest.mock import patch
# Mock the async HTTP handler
with patch(
diff --git a/tests/litellm_utils_tests/test_proxy_budget_reset.py b/tests/litellm_utils_tests/test_proxy_budget_reset.py
index a188fcf9d72..83891b55fb5 100644
--- a/tests/litellm_utils_tests/test_proxy_budget_reset.py
+++ b/tests/litellm_utils_tests/test_proxy_budget_reset.py
@@ -8,7 +8,6 @@ import pytest
from dotenv import load_dotenv
load_dotenv()
-import os
from litellm.proxy._types import LiteLLM_BudgetTableFull
diff --git a/tests/litellm_utils_tests/test_secret_manager.py b/tests/litellm_utils_tests/test_secret_manager.py
index 0f95fd75c53..012889ee00c 100644
--- a/tests/litellm_utils_tests/test_secret_manager.py
+++ b/tests/litellm_utils_tests/test_secret_manager.py
@@ -9,7 +9,6 @@ from dotenv import load_dotenv
import json
load_dotenv()
-import os
import tempfile
from uuid import uuid4
diff --git a/tests/llm_responses_api_testing/base_responses_api.py b/tests/llm_responses_api_testing/base_responses_api.py
index d5057944ba7..99ca9fb17b5 100644
--- a/tests/llm_responses_api_testing/base_responses_api.py
+++ b/tests/llm_responses_api_testing/base_responses_api.py
@@ -16,7 +16,6 @@ import litellm
from abc import ABC, abstractmethod
from litellm.integrations.custom_logger import CustomLogger
-import json
from litellm.types.utils import StandardLoggingPayload
from litellm.types.llms.openai import (
ResponseCompletedEvent,
diff --git a/tests/llm_responses_api_testing/conftest.py b/tests/llm_responses_api_testing/conftest.py
index 1928b540dad..b5884f51275 100644
--- a/tests/llm_responses_api_testing/conftest.py
+++ b/tests/llm_responses_api_testing/conftest.py
@@ -81,7 +81,6 @@ def setup_and_teardown():
0, os.path.abspath("../..")
) # Adds the project directory to the system path
- import litellm
importlib.reload(litellm)
diff --git a/tests/llm_responses_api_testing/test_anthropic_responses_api.py b/tests/llm_responses_api_testing/test_anthropic_responses_api.py
index 68ff22e8938..0ca159219df 100644
--- a/tests/llm_responses_api_testing/test_anthropic_responses_api.py
+++ b/tests/llm_responses_api_testing/test_anthropic_responses_api.py
@@ -24,7 +24,6 @@ from litellm.types.llms.openai import (
ResponseAPIUsage,
IncompleteDetails,
)
-import litellm
from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler
from base_responses_api import BaseResponsesAPITest
from openai.types.responses.function_tool import FunctionTool
diff --git a/tests/llm_responses_api_testing/test_azure_responses_api.py b/tests/llm_responses_api_testing/test_azure_responses_api.py
index ccef8cbf1e7..79990a88496 100644
--- a/tests/llm_responses_api_testing/test_azure_responses_api.py
+++ b/tests/llm_responses_api_testing/test_azure_responses_api.py
@@ -52,7 +52,7 @@ async def test_azure_responses_api_status_error():
Test that 'status' field is not sent in the final request body to Azure API.
The status field should be filtered out from input messages before making the API call.
"""
- from unittest.mock import AsyncMock, MagicMock
+ from unittest.mock import MagicMock
import json
request_data = {
@@ -193,7 +193,6 @@ async def test_azure_responses_api_headers_with_llm_provider_prefix():
in response._hidden_params["headers"] instead of additional_headers, making them
accessible via completion.headers in the same way as the completion API.
"""
- import json
import httpx
mock_response_data = {
diff --git a/tests/llm_responses_api_testing/test_openai_responses_api.py b/tests/llm_responses_api_testing/test_openai_responses_api.py
index d19fa09451c..d614c40f5d0 100644
--- a/tests/llm_responses_api_testing/test_openai_responses_api.py
+++ b/tests/llm_responses_api_testing/test_openai_responses_api.py
@@ -13,7 +13,6 @@ import json
sys.path.insert(0, os.path.abspath("../.."))
import litellm
from litellm.integrations.custom_logger import CustomLogger
-import json
from litellm.types.utils import StandardLoggingPayload
from litellm.types.llms.openai import (
ResponseCompletedEvent,
diff --git a/tests/llm_translation/test_anthropic_completion.py b/tests/llm_translation/test_anthropic_completion.py
index 7a478e494b1..ab1c67dffbf 100644
--- a/tests/llm_translation/test_anthropic_completion.py
+++ b/tests/llm_translation/test_anthropic_completion.py
@@ -14,7 +14,6 @@ from litellm.llms.anthropic.chat import ModelResponseIterator
load_dotenv()
import io
-import os
sys.path.insert(
0, os.path.abspath("../..")
@@ -360,7 +359,6 @@ def test_process_anthropic_headers_with_no_matching_headers():
)
def test_anthropic_tool_use(tool_type, tool_config, message_content):
"""Test Anthropic tool use with computer use and web fetch tools."""
- from litellm import completion
litellm._turn_on_debug()
@@ -951,7 +949,6 @@ def test_anthropic_citations_api():
"""
Test the citations API
"""
- from litellm import completion
try:
resp = completion(
@@ -997,7 +994,6 @@ def test_anthropic_citations_api():
def test_anthropic_citations_api_streaming():
- from litellm import completion
resp = completion(
model="claude-sonnet-4-5-20250929",
@@ -1044,7 +1040,6 @@ def test_anthropic_citations_api_streaming():
],
)
def test_anthropic_thinking_output(model):
- from litellm import completion
litellm._turn_on_debug()
@@ -1111,7 +1106,6 @@ def test_anthropic_thinking_output_stream(model):
def test_anthropic_custom_headers():
- from litellm import completion
from litellm.llms.custom_httpx.http_handler import HTTPHandler
client = HTTPHandler()
@@ -1528,7 +1522,6 @@ def test_anthropic_tool_cache_control():
def test_anthropic_streaming():
- from litellm import completion
request_data = {
"messages": [
diff --git a/tests/llm_translation/test_azure_ai.py b/tests/llm_translation/test_azure_ai.py
index d2d893a611b..553f9102246 100644
--- a/tests/llm_translation/test_azure_ai.py
+++ b/tests/llm_translation/test_azure_ai.py
@@ -19,7 +19,6 @@ from litellm.llms.custom_httpx.http_handler import HTTPHandler
load_dotenv()
import io
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/llm_translation/test_azure_openai.py b/tests/llm_translation/test_azure_openai.py
index eb5ba44c410..0deb20900a7 100644
--- a/tests/llm_translation/test_azure_openai.py
+++ b/tests/llm_translation/test_azure_openai.py
@@ -255,7 +255,6 @@ def test_get_azure_ad_token_from_username_password(
def test_azure_openai_gpt_4o_naming(monkeypatch):
- from openai import AzureOpenAI
from pydantic import BaseModel, Field
monkeypatch.setenv("AZURE_API_VERSION", "2024-10-21")
@@ -302,7 +301,6 @@ def test_azure_gpt_4o_with_tool_call_and_response_format(api_version):
from pydantic import BaseModel
import litellm
- from openai import AzureOpenAI
client = AzureOpenAI(
api_key="fake-key",
diff --git a/tests/llm_translation/test_bedrock_agents.py b/tests/llm_translation/test_bedrock_agents.py
index 590e061c60d..6371224def9 100644
--- a/tests/llm_translation/test_bedrock_agents.py
+++ b/tests/llm_translation/test_bedrock_agents.py
@@ -8,7 +8,6 @@ import litellm.types
load_dotenv()
import io
-import os
import json
sys.path.insert(
@@ -67,7 +66,7 @@ async def test_bedrock_agents_with_streaming():
def test_bedrock_agents_with_custom_params():
litellm._turn_on_debug()
- from unittest.mock import MagicMock, patch
+ from unittest.mock import MagicMock
from litellm.llms.custom_httpx.http_handler import HTTPHandler
client = HTTPHandler()
diff --git a/tests/llm_translation/test_bedrock_completion.py b/tests/llm_translation/test_bedrock_completion.py
index 9534bc8de3c..6ee6e5d1493 100644
--- a/tests/llm_translation/test_bedrock_completion.py
+++ b/tests/llm_translation/test_bedrock_completion.py
@@ -13,7 +13,6 @@ import litellm.types
load_dotenv()
import io
-import os
import json
sys.path.insert(
diff --git a/tests/llm_translation/test_bedrock_dynamic_auth_params_unit_tests.py b/tests/llm_translation/test_bedrock_dynamic_auth_params_unit_tests.py
index 19662ae8ba6..5d2fab15a8f 100644
--- a/tests/llm_translation/test_bedrock_dynamic_auth_params_unit_tests.py
+++ b/tests/llm_translation/test_bedrock_dynamic_auth_params_unit_tests.py
@@ -15,13 +15,7 @@ from litellm.llms.custom_httpx.http_handler import HTTPHandler
from unittest.mock import Mock
from litellm.llms.bedrock.base_aws_llm import BaseAWSLLM
-import json
-import pytest
-from unittest.mock import patch, Mock
-import litellm
-from litellm.llms.custom_httpx.http_handler import HTTPHandler
-from litellm.llms.bedrock.base_aws_llm import BaseAWSLLM
def test_bedrock_completion_with_region_name():
diff --git a/tests/llm_translation/test_bedrock_govcloud.py b/tests/llm_translation/test_bedrock_govcloud.py
index 1e8504648f8..e69a95c714d 100644
--- a/tests/llm_translation/test_bedrock_govcloud.py
+++ b/tests/llm_translation/test_bedrock_govcloud.py
@@ -475,7 +475,6 @@ class TestBedrockGovCloudSupport:
@patch("litellm.llms.custom_httpx.http_handler.HTTPHandler.post")
def test_govcloud_completion_with_cost_tracking(self, mock_post):
"""Test that completion requests with cost tracking use correct pricing for GovCloud models"""
- from litellm import completion
from unittest.mock import Mock
import json
diff --git a/tests/llm_translation/test_cohere.py b/tests/llm_translation/test_cohere.py
index 2d719cbde36..0eb0b1b33fe 100644
--- a/tests/llm_translation/test_cohere.py
+++ b/tests/llm_translation/test_cohere.py
@@ -6,7 +6,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
-import os
sys.path.insert(
0, os.path.abspath("../..")
@@ -18,7 +17,6 @@ import pytest
import litellm
from litellm import RateLimitError, Timeout, completion, completion_cost, embedding
from unittest.mock import AsyncMock, patch
-from litellm import RateLimitError, Timeout, completion, completion_cost, embedding
from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler
litellm.num_retries = 3
diff --git a/tests/llm_translation/test_infinity.py b/tests/llm_translation/test_infinity.py
index 25296290a12..5ca3d377fd7 100644
--- a/tests/llm_translation/test_infinity.py
+++ b/tests/llm_translation/test_infinity.py
@@ -11,11 +11,9 @@ sys.path.insert(
import litellm
-import json
import os
import sys
-from datetime import datetime
-from unittest.mock import patch, MagicMock, AsyncMock
+from unittest.mock import patch, MagicMock
import pytest
@@ -23,7 +21,6 @@ sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system-path
from test_rerank import assert_response_shape
-import litellm
from base_embedding_unit_tests import BaseLLMEmbeddingTest
from litellm.llms.custom_httpx.http_handler import HTTPHandler, AsyncHTTPHandler
diff --git a/tests/llm_translation/test_minimax_tts.py b/tests/llm_translation/test_minimax_tts.py
index 2e3e97888e9..e10b32fb39b 100644
--- a/tests/llm_translation/test_minimax_tts.py
+++ b/tests/llm_translation/test_minimax_tts.py
@@ -139,7 +139,6 @@ class TestMinimaxTextToSpeechConfig:
# Mock both litellm.api_key and get_secret_str to return None
import litellm
- from unittest.mock import patch
original_api_key = litellm.api_key
try:
@@ -274,7 +273,6 @@ class TestMinimaxSpeechIntegration:
def test_speech_mock_response(self):
"""Test speech synthesis with mocked response"""
- from unittest.mock import MagicMock, patch
# Create mock audio data (hex-encoded as MiniMax returns)
mock_audio_bytes = b"fake audio data for testing"
diff --git a/tests/llm_translation/test_mistral_api.py b/tests/llm_translation/test_mistral_api.py
index 8cf704fbe89..62f69e616ab 100644
--- a/tests/llm_translation/test_mistral_api.py
+++ b/tests/llm_translation/test_mistral_api.py
@@ -11,7 +11,6 @@ from litellm.llms.anthropic.chat import ModelResponseIterator
load_dotenv()
import io
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/llm_translation/test_nvidia_nim.py b/tests/llm_translation/test_nvidia_nim.py
index 80e764147bb..79c792d1644 100644
--- a/tests/llm_translation/test_nvidia_nim.py
+++ b/tests/llm_translation/test_nvidia_nim.py
@@ -11,13 +11,12 @@ sys.path.insert(
import httpx
import pytest
-from unittest.mock import patch, MagicMock, AsyncMock
+from unittest.mock import patch, MagicMock
import litellm
from litellm import Choices, Message, ModelResponse, EmbeddingResponse, Usage
from litellm import completion
from base_rerank_unit_tests import BaseLLMRerankTest
-import litellm
def test_completion_nvidia_nim():
diff --git a/tests/llm_translation/test_openai_o1.py b/tests/llm_translation/test_openai_o1.py
index fccb1c6f1e3..dbaf20717a0 100644
--- a/tests/llm_translation/test_openai_o1.py
+++ b/tests/llm_translation/test_openai_o1.py
@@ -134,7 +134,6 @@ def test_litellm_responses():
"""
ensures that type of completion_tokens_details is correctly handled / returned
"""
- from litellm import ModelResponse
from litellm.types.utils import CompletionTokensDetails
response = ModelResponse(
diff --git a/tests/llm_translation/test_rerank.py b/tests/llm_translation/test_rerank.py
index d784677060a..cb254542009 100644
--- a/tests/llm_translation/test_rerank.py
+++ b/tests/llm_translation/test_rerank.py
@@ -8,7 +8,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
-import os
from typing import Optional, Dict
sys.path.insert(
diff --git a/tests/llm_translation/test_text_completion_unit_tests.py b/tests/llm_translation/test_text_completion_unit_tests.py
index 04145cf6ce0..55026ba0542 100644
--- a/tests/llm_translation/test_text_completion_unit_tests.py
+++ b/tests/llm_translation/test_text_completion_unit_tests.py
@@ -6,7 +6,7 @@ from unittest.mock import AsyncMock
import pytest
import httpx
from respx import MockRouter
-from unittest.mock import patch, MagicMock, AsyncMock
+from unittest.mock import patch, MagicMock
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/llm_translation/test_triton.py b/tests/llm_translation/test_triton.py
index f4a26360a6c..f9ab3bfaff7 100644
--- a/tests/llm_translation/test_triton.py
+++ b/tests/llm_translation/test_triton.py
@@ -15,9 +15,7 @@ sys.path.insert(
import pytest
import litellm
-import pytest
from litellm.llms.triton.embedding.transformation import TritonEmbeddingConfig
-import litellm
from tests.fake_openai_endpoint import FAKE_OPENAI_API_BASE
diff --git a/tests/llm_translation/test_unit_test_bedrock_invoke.py b/tests/llm_translation/test_unit_test_bedrock_invoke.py
index 39f02263f03..586b04384d5 100644
--- a/tests/llm_translation/test_unit_test_bedrock_invoke.py
+++ b/tests/llm_translation/test_unit_test_bedrock_invoke.py
@@ -9,7 +9,6 @@ import json
load_dotenv()
import io
-import os
sys.path.insert(0, os.path.abspath("../.."))
from unittest.mock import AsyncMock, Mock, patch
diff --git a/tests/load_tests/conftest.py b/tests/load_tests/conftest.py
new file mode 100644
index 00000000000..48a98663e4e
--- /dev/null
+++ b/tests/load_tests/conftest.py
@@ -0,0 +1,5 @@
+from tests.load_tests.memory_leak_utils import ( # noqa: F401 # re-exported so pytest resolves these fixtures by name
+ limit_memory,
+ mock_server,
+ test_router,
+)
diff --git a/tests/load_tests/test_linear_memory_growth.py b/tests/load_tests/test_linear_memory_growth.py
index 46bab344f4e..f1c36924a2a 100644
--- a/tests/load_tests/test_linear_memory_growth.py
+++ b/tests/load_tests/test_linear_memory_growth.py
@@ -21,12 +21,7 @@ pytest tests/load_tests/test_linear_memory_growth.py -v
import pytest
-from tests.load_tests.memory_leak_utils import (
- limit_memory, # noqa: F401 # pytest fixture used via dependency injection
- mock_server, # noqa: F401 # pytest fixture used via dependency injection
- run_memory_baseline_test,
- test_router, # noqa: F401 # pytest fixture used via dependency injection
-)
+from tests.load_tests.memory_leak_utils import run_memory_baseline_test
# Memory limit for all linear memory growth tests
MEMORY_LIMIT = "40 MB"
diff --git a/tests/load_tests/test_memory_usage.py b/tests/load_tests/test_memory_usage.py
index f273865a29a..347dbf2bb44 100644
--- a/tests/load_tests/test_memory_usage.py
+++ b/tests/load_tests/test_memory_usage.py
@@ -8,7 +8,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
-import os
sys.path.insert(
0, os.path.abspath("../..")
@@ -21,13 +20,11 @@ from litellm.router import Router
from typing import Optional
from unittest.mock import MagicMock, patch
-import asyncio
import pytest
import os
import litellm
from typing import Callable, Any
-import tracemalloc
import gc
from typing import Type
from pydantic import BaseModel
diff --git a/tests/local_testing/cache_unit_tests.py b/tests/local_testing/cache_unit_tests.py
index d29eed33687..27eefb79fae 100644
--- a/tests/local_testing/cache_unit_tests.py
+++ b/tests/local_testing/cache_unit_tests.py
@@ -9,7 +9,6 @@ from litellm._uuid import uuid
from dotenv import load_dotenv
load_dotenv()
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/local_testing/test_acompletion_fallbacks.py b/tests/local_testing/test_acompletion_fallbacks.py
index 00c2139f278..2d282f4f4f6 100644
--- a/tests/local_testing/test_acompletion_fallbacks.py
+++ b/tests/local_testing/test_acompletion_fallbacks.py
@@ -12,7 +12,6 @@ sys.path.insert(
import concurrent
from dotenv import load_dotenv
-import asyncio
import litellm
diff --git a/tests/local_testing/test_aim_guardrails.py b/tests/local_testing/test_aim_guardrails.py
index 5e5fb0d5459..a6a4a0ad781 100644
--- a/tests/local_testing/test_aim_guardrails.py
+++ b/tests/local_testing/test_aim_guardrails.py
@@ -463,7 +463,6 @@ async def test_post_call_stream__all_chunks_are_valid(monkeypatch, length: int):
@pytest.mark.asyncio
async def test_post_call_stream__blocked_chunks(monkeypatch):
- from litellm.proxy.proxy_server import StreamingCallbackError
init_guardrails_v2(
all_guardrails=[
diff --git a/tests/local_testing/test_amazing_vertex_completion.py b/tests/local_testing/test_amazing_vertex_completion.py
index 9bd64719102..a52b5975f6e 100644
--- a/tests/local_testing/test_amazing_vertex_completion.py
+++ b/tests/local_testing/test_amazing_vertex_completion.py
@@ -6,7 +6,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
-import os
from test_streaming import streaming_format_tests
diff --git a/tests/local_testing/test_anthropic_prompt_caching.py b/tests/local_testing/test_anthropic_prompt_caching.py
index ef374de5e2a..3105c0b9eeb 100644
--- a/tests/local_testing/test_anthropic_prompt_caching.py
+++ b/tests/local_testing/test_anthropic_prompt_caching.py
@@ -7,7 +7,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
-import os
from test_streaming import streaming_format_tests
@@ -210,7 +209,6 @@ def anthropic_messages():
@pytest.mark.asyncio
async def test_anthropic_vertex_ai_prompt_caching(anthropic_messages, sync_mode):
litellm._turn_on_debug()
- from litellm.llms.custom_httpx.http_handler import HTTPHandler, AsyncHTTPHandler
load_vertex_ai_credentials()
diff --git a/tests/local_testing/test_auth_utils.py b/tests/local_testing/test_auth_utils.py
index 88e8c02a606..e1444ed562e 100644
--- a/tests/local_testing/test_auth_utils.py
+++ b/tests/local_testing/test_auth_utils.py
@@ -6,7 +6,6 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/local_testing/test_azure_openai.py b/tests/local_testing/test_azure_openai.py
index 1b99140b6e6..2a2b1e7fc35 100644
--- a/tests/local_testing/test_azure_openai.py
+++ b/tests/local_testing/test_azure_openai.py
@@ -7,7 +7,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/local_testing/test_basic_python_version.py b/tests/local_testing/test_basic_python_version.py
index 1f260f86eeb..a710b5e0ff7 100644
--- a/tests/local_testing/test_basic_python_version.py
+++ b/tests/local_testing/test_basic_python_version.py
@@ -215,9 +215,7 @@ def test_locked_aiohttp_version_is_not_pool_poisoning():
import os
import subprocess
-import time
-import pytest
import requests
diff --git a/tests/local_testing/test_blocked_user_list.py b/tests/local_testing/test_blocked_user_list.py
index 44265afd890..9b29d3fcfa5 100644
--- a/tests/local_testing/test_blocked_user_list.py
+++ b/tests/local_testing/test_blocked_user_list.py
@@ -14,12 +14,10 @@ from dotenv import load_dotenv
from fastapi import Request
load_dotenv()
-import os
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
-import asyncio
import logging
import pytest
@@ -57,7 +55,6 @@ verbose_proxy_logger.setLevel(level=logging.DEBUG)
from starlette.datastructures import URL
-from litellm.caching.caching import DualCache
from litellm.proxy._types import (
BlockUsers,
DynamoDBArgs,
diff --git a/tests/local_testing/test_braintrust.py b/tests/local_testing/test_braintrust.py
index c6e37af702a..18c210b6d33 100644
--- a/tests/local_testing/test_braintrust.py
+++ b/tests/local_testing/test_braintrust.py
@@ -13,12 +13,10 @@ from dotenv import load_dotenv
from fastapi import Request
load_dotenv()
-import os
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
-import asyncio
import logging
from unittest.mock import AsyncMock, MagicMock, patch
@@ -29,7 +27,6 @@ from litellm.llms.custom_httpx.http_handler import HTTPHandler
def test_braintrust_logging():
- import litellm
litellm.set_verbose = True
@@ -53,7 +50,6 @@ def test_braintrust_logging():
def test_braintrust_logging_specific_project_id():
- import litellm
litellm.set_verbose = True
diff --git a/tests/local_testing/test_caching.py b/tests/local_testing/test_caching.py
index 0c7c0157651..90be551ff46 100644
--- a/tests/local_testing/test_caching.py
+++ b/tests/local_testing/test_caching.py
@@ -7,7 +7,6 @@ from litellm._uuid import uuid
from dotenv import load_dotenv
load_dotenv()
-import os
import json
sys.path.insert(
@@ -33,7 +32,6 @@ from datetime import timedelta
messages = [{"role": "user", "content": "who is ishaan Github? "}]
# comment
-import random
import string
diff --git a/tests/local_testing/test_caching_ssl.py b/tests/local_testing/test_caching_ssl.py
index 21782963250..863f227aef1 100644
--- a/tests/local_testing/test_caching_ssl.py
+++ b/tests/local_testing/test_caching_ssl.py
@@ -7,7 +7,6 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/local_testing/test_completion.py b/tests/local_testing/test_completion.py
index 5b0bff65959..c7cd5a1a2d4 100644
--- a/tests/local_testing/test_completion.py
+++ b/tests/local_testing/test_completion.py
@@ -7,7 +7,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
-import os
sys.path.insert(
0, os.path.abspath("../..")
@@ -1380,7 +1379,6 @@ def test_ollama_image():
"""
import base64
- import io
from PIL import Image
diff --git a/tests/local_testing/test_completion_with_retries.py b/tests/local_testing/test_completion_with_retries.py
index 4edd51920f3..c9b519b2af8 100644
--- a/tests/local_testing/test_completion_with_retries.py
+++ b/tests/local_testing/test_completion_with_retries.py
@@ -3,7 +3,6 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
-import os
sys.path.insert(
0, os.path.abspath("../..")
@@ -207,7 +206,6 @@ async def test_responses_retry_on_auth_error(sync_mode):
This validates that the @client decorator properly handles responses/aresponses retries.
"""
from unittest.mock import patch
- import openai
num_retries = 2
diff --git a/tests/local_testing/test_config.py b/tests/local_testing/test_config.py
index 0c4c1a39b98..2a5dc3376ee 100644
--- a/tests/local_testing/test_config.py
+++ b/tests/local_testing/test_config.py
@@ -10,7 +10,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/local_testing/test_cost_calc.py b/tests/local_testing/test_cost_calc.py
index 3623af59848..233b67a6072 100644
--- a/tests/local_testing/test_cost_calc.py
+++ b/tests/local_testing/test_cost_calc.py
@@ -6,7 +6,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/local_testing/test_dual_cache.py b/tests/local_testing/test_dual_cache.py
index 5a1cdf86487..cdfa8146420 100644
--- a/tests/local_testing/test_dual_cache.py
+++ b/tests/local_testing/test_dual_cache.py
@@ -7,7 +7,6 @@ from litellm._uuid import uuid
from dotenv import load_dotenv
load_dotenv()
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/local_testing/test_dynamic_rate_limit_handler.py b/tests/local_testing/test_dynamic_rate_limit_handler.py
index fac7ce10397..373949a81ac 100644
--- a/tests/local_testing/test_dynamic_rate_limit_handler.py
+++ b/tests/local_testing/test_dynamic_rate_limit_handler.py
@@ -13,7 +13,6 @@ from typing import Optional, Tuple
from dotenv import load_dotenv
load_dotenv()
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/local_testing/test_embedding.py b/tests/local_testing/test_embedding.py
index f4c61e99547..ee9d4cdd915 100644
--- a/tests/local_testing/test_embedding.py
+++ b/tests/local_testing/test_embedding.py
@@ -314,7 +314,6 @@ def test_openai_azure_embedding():
pytest.fail(f"Error occurred: {e}")
-from openai.types.embedding import Embedding
def _openai_mock_response(*args, **kwargs):
@@ -570,7 +569,6 @@ def test_hf_embedding():
# test_hf_embedding()
-from unittest.mock import MagicMock, patch
def tgi_mock_post(*args, **kwargs):
diff --git a/tests/local_testing/test_function_call_parsing.py b/tests/local_testing/test_function_call_parsing.py
index f9582fcc574..57027c670bb 100644
--- a/tests/local_testing/test_function_call_parsing.py
+++ b/tests/local_testing/test_function_call_parsing.py
@@ -8,7 +8,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/local_testing/test_function_calling.py b/tests/local_testing/test_function_calling.py
index d6adde84400..b5f72264549 100644
--- a/tests/local_testing/test_function_calling.py
+++ b/tests/local_testing/test_function_calling.py
@@ -6,7 +6,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/local_testing/test_function_setup.py b/tests/local_testing/test_function_setup.py
index b5e716c7314..92f49589ca2 100644
--- a/tests/local_testing/test_function_setup.py
+++ b/tests/local_testing/test_function_setup.py
@@ -5,7 +5,7 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
-import os, io
+import io
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/local_testing/test_get_optional_params_embeddings.py b/tests/local_testing/test_get_optional_params_embeddings.py
index 667207de789..ddf9e877477 100644
--- a/tests/local_testing/test_get_optional_params_embeddings.py
+++ b/tests/local_testing/test_get_optional_params_embeddings.py
@@ -5,7 +5,7 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
-import os, io
+import io
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/local_testing/test_helicone_integration.py b/tests/local_testing/test_helicone_integration.py
index 4c62ee259a3..9bfa29551e3 100644
--- a/tests/local_testing/test_helicone_integration.py
+++ b/tests/local_testing/test_helicone_integration.py
@@ -131,7 +131,6 @@ def test_helicone_removes_otel_span_from_metadata():
to prevent JSON serialization errors.
"""
from litellm.integrations.helicone import HeliconeLogger
- from unittest.mock import MagicMock
# Create a mock span object (similar to what OpenTelemetry would create)
mock_span = MagicMock()
diff --git a/tests/local_testing/test_least_busy_routing.py b/tests/local_testing/test_least_busy_routing.py
index 0f4f6923a19..0a3b5490131 100644
--- a/tests/local_testing/test_least_busy_routing.py
+++ b/tests/local_testing/test_least_busy_routing.py
@@ -11,7 +11,6 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/local_testing/test_llm_guard.py b/tests/local_testing/test_llm_guard.py
index 86fa80ee944..60fe9c0e020 100644
--- a/tests/local_testing/test_llm_guard.py
+++ b/tests/local_testing/test_llm_guard.py
@@ -9,7 +9,6 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/local_testing/test_lowest_cost_routing.py b/tests/local_testing/test_lowest_cost_routing.py
index 4e8b06fb628..6ed1731572a 100644
--- a/tests/local_testing/test_lowest_cost_routing.py
+++ b/tests/local_testing/test_lowest_cost_routing.py
@@ -7,7 +7,7 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
-import os, copy
+import copy
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/local_testing/test_lowest_latency_routing.py b/tests/local_testing/test_lowest_latency_routing.py
index ac84b3ec5e9..0a202e0dfb9 100644
--- a/tests/local_testing/test_lowest_latency_routing.py
+++ b/tests/local_testing/test_lowest_latency_routing.py
@@ -13,7 +13,6 @@ from dotenv import load_dotenv
load_dotenv()
import copy
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/local_testing/test_ollama.py b/tests/local_testing/test_ollama.py
index 3a997c3d4a8..7ca8e806529 100644
--- a/tests/local_testing/test_ollama.py
+++ b/tests/local_testing/test_ollama.py
@@ -8,7 +8,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/local_testing/test_openai_moderations_hook.py b/tests/local_testing/test_openai_moderations_hook.py
index c4298035443..2e24740c929 100644
--- a/tests/local_testing/test_openai_moderations_hook.py
+++ b/tests/local_testing/test_openai_moderations_hook.py
@@ -9,7 +9,6 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
-import os
sys.path.insert(
0, os.path.abspath("../..")
@@ -42,8 +41,6 @@ async def test_openai_moderation_error_raising(monkeypatch):
user_api_key_dict = UserAPIKeyAuth(api_key=_api_key)
local_cache = DualCache()
- from litellm.proxy.proxy_server import llm_router
-
llm_router = litellm.Router(
model_list=[
{
diff --git a/tests/local_testing/test_prompt_injection_detection.py b/tests/local_testing/test_prompt_injection_detection.py
index b1a9aff1584..9f5137630ea 100644
--- a/tests/local_testing/test_prompt_injection_detection.py
+++ b/tests/local_testing/test_prompt_injection_detection.py
@@ -7,7 +7,6 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/local_testing/test_pydantic.py b/tests/local_testing/test_pydantic.py
index 8b410544067..436b9d3dd48 100644
--- a/tests/local_testing/test_pydantic.py
+++ b/tests/local_testing/test_pydantic.py
@@ -6,7 +6,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/local_testing/test_router_budget_limiter.py b/tests/local_testing/test_router_budget_limiter.py
index 4ef99ec8c12..3bdb3116670 100644
--- a/tests/local_testing/test_router_budget_limiter.py
+++ b/tests/local_testing/test_router_budget_limiter.py
@@ -4,7 +4,7 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
-import os, copy
+import copy
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/local_testing/test_router_cooldown_handlers.py b/tests/local_testing/test_router_cooldown_handlers.py
index fdc89fc04ed..55510df5b9e 100644
--- a/tests/local_testing/test_router_cooldown_handlers.py
+++ b/tests/local_testing/test_router_cooldown_handlers.py
@@ -536,7 +536,6 @@ async def test_high_traffic_cooldowns_all_healthy_deployments():
all_deployment_ids = router.get_model_ids()
- import random
from collections import defaultdict
# Create a defaultdict to track successes and failures for each model ID
@@ -629,7 +628,6 @@ async def test_high_traffic_cooldowns_one_bad_deployment():
all_deployment_ids = router.get_model_ids()
- import random
from collections import defaultdict
# Create a defaultdict to track successes and failures for each model ID
@@ -727,7 +725,6 @@ async def test_high_traffic_cooldowns_one_rate_limited_deployment():
all_deployment_ids = router.get_model_ids()
- import random
from collections import defaultdict
# Create a defaultdict to track successes and failures for each model ID
diff --git a/tests/local_testing/test_router_debug_logs.py b/tests/local_testing/test_router_debug_logs.py
index ad807539bf2..04e8dc6c77c 100644
--- a/tests/local_testing/test_router_debug_logs.py
+++ b/tests/local_testing/test_router_debug_logs.py
@@ -10,7 +10,6 @@ sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
-import asyncio
import logging
import litellm
diff --git a/tests/local_testing/test_router_timeout.py b/tests/local_testing/test_router_timeout.py
index cdd9ae5c538..9971e540024 100644
--- a/tests/local_testing/test_router_timeout.py
+++ b/tests/local_testing/test_router_timeout.py
@@ -150,7 +150,6 @@ def test_router_timeout_with_retries_anthropic_model(num_retries, expected_call_
If request hits custom timeout, ensure it's retried.
"""
from litellm.llms.custom_httpx.http_handler import HTTPHandler
- import time
litellm.num_retries = num_retries
litellm.request_timeout = 0.000001
diff --git a/tests/local_testing/test_sagemaker.py b/tests/local_testing/test_sagemaker.py
index d4c5a5a857f..bf17d9dce21 100644
--- a/tests/local_testing/test_sagemaker.py
+++ b/tests/local_testing/test_sagemaker.py
@@ -7,7 +7,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
-import os
import litellm
from test_streaming import streaming_format_tests
@@ -20,7 +19,6 @@ from unittest.mock import AsyncMock, MagicMock, patch
import pytest
-import litellm
from litellm import RateLimitError, Timeout, completion, completion_cost, embedding
from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandler
from litellm.litellm_core_utils.prompt_templates.factory import anthropic_messages_pt
diff --git a/tests/local_testing/test_secret_detect_hook.py b/tests/local_testing/test_secret_detect_hook.py
index ad2e248da1b..8a93b72dce2 100644
--- a/tests/local_testing/test_secret_detect_hook.py
+++ b/tests/local_testing/test_secret_detect_hook.py
@@ -15,7 +15,6 @@ from datetime import datetime
from dotenv import load_dotenv
load_dotenv()
-import os
sys.path.insert(
0, os.path.abspath("../..")
@@ -34,7 +33,6 @@ from litellm_enterprise.enterprise_callbacks.secret_detection import (
)
from litellm.proxy.proxy_server import chat_completion
from litellm.proxy.utils import ProxyLogging, hash_token
-from litellm.router import Router
from tests.fake_openai_endpoint import FAKE_OPENAI_API_BASE
diff --git a/tests/local_testing/test_stream_chunk_builder.py b/tests/local_testing/test_stream_chunk_builder.py
index 664fd936205..9dab6e60c35 100644
--- a/tests/local_testing/test_stream_chunk_builder.py
+++ b/tests/local_testing/test_stream_chunk_builder.py
@@ -9,11 +9,11 @@ from typing import List
from litellm.types.utils import StreamingChoices, ChatCompletionAudioResponse
-def check_non_streaming_response(completion):
- assert completion.choices[0].message.audio is not None, "Audio response is missing"
- print("audio", completion.choices[0].message.audio)
+def check_non_streaming_response(response):
+ assert response.choices[0].message.audio is not None, "Audio response is missing"
+ print("audio", response.choices[0].message.audio)
assert isinstance(
- completion.choices[0].message.audio, ChatCompletionAudioResponse
+ response.choices[0].message.audio, ChatCompletionAudioResponse
), "Invalid audio response type"
assert len(completion.choices[0].message.audio.data) > 0, "Audio data is empty"
@@ -594,7 +594,6 @@ def test_stream_chunk_builder_multiple_tool_calls():
def test_stream_chunk_builder_openai_prompt_caching():
- from openai import OpenAI
from pydantic import BaseModel
client = OpenAI(
@@ -639,7 +638,6 @@ def test_stream_chunk_builder_openai_prompt_caching():
@pytest.mark.flaky(retries=5, delay=2)
def test_stream_chunk_builder_openai_audio_output_usage():
from pydantic import BaseModel
- from openai import OpenAI
from typing import Optional
client = OpenAI(
@@ -720,7 +718,6 @@ def test_stream_chunk_builder_tool_calls_list():
Function,
ModelResponseStream,
Delta,
- StreamingChoices,
ChatCompletionDeltaToolCall,
)
diff --git a/tests/local_testing/test_streaming.py b/tests/local_testing/test_streaming.py
index 1fe9a1ab297..ba1f4e7d51c 100644
--- a/tests/local_testing/test_streaming.py
+++ b/tests/local_testing/test_streaming.py
@@ -951,7 +951,6 @@ def test_vertex_ai_stream(provider):
load_vertex_ai_credentials()
litellm.set_verbose = True
- import random
test_models = ["gemini-2.5-flash-lite"]
for model in test_models:
@@ -2352,7 +2351,6 @@ def test_success_callback_streaming():
from typing import List, Optional
#### STREAMING + FUNCTION CALLING ###
-from pydantic import BaseModel
class Function(BaseModel):
@@ -2569,7 +2567,6 @@ def test_azure_streaming_and_function_calling():
@pytest.mark.asyncio
async def test_azure_astreaming_and_function_calling():
- from litellm._uuid import uuid
tools = [
{
diff --git a/tests/local_testing/test_text_completion.py b/tests/local_testing/test_text_completion.py
index 63cee71f999..227d8e5096a 100644
--- a/tests/local_testing/test_text_completion.py
+++ b/tests/local_testing/test_text_completion.py
@@ -8,7 +8,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/local_testing/test_tpm_rpm_routing_v2.py b/tests/local_testing/test_tpm_rpm_routing_v2.py
index 211af566424..c6917775d4b 100644
--- a/tests/local_testing/test_tpm_rpm_routing_v2.py
+++ b/tests/local_testing/test_tpm_rpm_routing_v2.py
@@ -12,7 +12,6 @@ from typing import Dict
from dotenv import load_dotenv
load_dotenv()
-import os
sys.path.insert(
0, os.path.abspath("../..")
@@ -399,9 +398,7 @@ async def test_multiple_potential_deployments(sync_mode):
def test_single_deployment_tpm_zero():
import os
- from datetime import datetime
- import litellm
model_list = [
{
diff --git a/tests/local_testing/test_update_spend.py b/tests/local_testing/test_update_spend.py
index 2e13c3f82cf..7894f330796 100644
--- a/tests/local_testing/test_update_spend.py
+++ b/tests/local_testing/test_update_spend.py
@@ -14,12 +14,10 @@ from dotenv import load_dotenv
from fastapi import Request
load_dotenv()
-import os
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
-import asyncio
import logging
import pytest
@@ -54,7 +52,6 @@ verbose_proxy_logger.setLevel(level=logging.DEBUG)
from starlette.datastructures import URL
-from litellm.caching.caching import DualCache
from litellm.proxy._types import (
BlockUsers,
DynamoDBArgs,
diff --git a/tests/logging_callback_tests/test_alerting.py b/tests/logging_callback_tests/test_alerting.py
index 7cf88d49e22..83513107ad3 100644
--- a/tests/logging_callback_tests/test_alerting.py
+++ b/tests/logging_callback_tests/test_alerting.py
@@ -19,7 +19,6 @@ from litellm.types.integrations.slack_alerting import AlertType
# import logging
# logging.basicConfig(level=logging.DEBUG)
sys.path.insert(0, os.path.abspath("../.."))
-import asyncio
import os
import unittest.mock
from unittest.mock import AsyncMock, MagicMock, patch
@@ -132,8 +131,6 @@ def test_init():
print("passed testing slack alerting init")
-from datetime import datetime, timedelta
-from unittest.mock import AsyncMock, patch
@pytest.fixture
@@ -342,7 +339,6 @@ async def test_daily_reports_redis_cache_scheduler():
# we need this to be 0 so it actualy sends the report
slack_alerting.alerting_args.daily_report_frequency = 0
- from litellm.router import AlertingConfig
router = litellm.Router(
model_list=[
@@ -382,7 +378,6 @@ async def test_daily_reports_redis_cache_scheduler():
@pytest.mark.asyncio
@pytest.mark.skip(reason="Local test. Test if slack alerts are sent.")
async def test_send_llm_exception_to_slack():
- from litellm.router import AlertingConfig
# on async success
router = litellm.Router(
diff --git a/tests/logging_callback_tests/test_built_in_tools_cost_tracking.py b/tests/logging_callback_tests/test_built_in_tools_cost_tracking.py
index 0e73ad834da..942c26438c8 100644
--- a/tests/logging_callback_tests/test_built_in_tools_cost_tracking.py
+++ b/tests/logging_callback_tests/test_built_in_tools_cost_tracking.py
@@ -9,7 +9,6 @@ from fastapi.routing import APIRoute
load_dotenv()
import io
-import os
import time
import json
@@ -102,7 +101,6 @@ async def test_openai_web_search_logging_cost_tracking(
):
"""Test web search cost tracking with different search context sizes"""
test_custom_logger = await _setup_web_search_test()
- from litellm._uuid import uuid
request_kwargs = {
"model": "openai/gpt-5-search-api",
diff --git a/tests/logging_callback_tests/test_gcs_pub_sub.py b/tests/logging_callback_tests/test_gcs_pub_sub.py
index 3c242a5fe1d..2f6cdb63192 100644
--- a/tests/logging_callback_tests/test_gcs_pub_sub.py
+++ b/tests/logging_callback_tests/test_gcs_pub_sub.py
@@ -15,7 +15,6 @@ from unittest.mock import AsyncMock, patch
import pytest
-import litellm
from litellm import completion
from litellm._logging import verbose_logger
from litellm.integrations.gcs_pubsub.pub_sub import *
diff --git a/tests/logging_callback_tests/test_generic_api_callback.py b/tests/logging_callback_tests/test_generic_api_callback.py
index fbe74d017a6..9ad17b3d6e2 100644
--- a/tests/logging_callback_tests/test_generic_api_callback.py
+++ b/tests/logging_callback_tests/test_generic_api_callback.py
@@ -16,7 +16,6 @@ from unittest.mock import AsyncMock, patch
import pytest
-import litellm
from litellm import completion
from litellm._logging import verbose_logger
from litellm.integrations.gcs_pubsub.pub_sub import *
diff --git a/tests/logging_callback_tests/test_moderations_api_logging.py b/tests/logging_callback_tests/test_moderations_api_logging.py
index 0ae3580917d..9190f2aebe5 100644
--- a/tests/logging_callback_tests/test_moderations_api_logging.py
+++ b/tests/logging_callback_tests/test_moderations_api_logging.py
@@ -9,7 +9,6 @@ from fastapi.routing import APIRoute
load_dotenv()
import io
-import os
import time
import json
diff --git a/tests/logging_callback_tests/test_opentelemetry_unit_tests.py b/tests/logging_callback_tests/test_opentelemetry_unit_tests.py
index e8ca84a78ad..767f840a003 100644
--- a/tests/logging_callback_tests/test_opentelemetry_unit_tests.py
+++ b/tests/logging_callback_tests/test_opentelemetry_unit_tests.py
@@ -9,8 +9,6 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
-import os
-import asyncio
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/logging_callback_tests/test_spend_logs.py b/tests/logging_callback_tests/test_spend_logs.py
index f9c4db7c6d5..709aa81f421 100644
--- a/tests/logging_callback_tests/test_spend_logs.py
+++ b/tests/logging_callback_tests/test_spend_logs.py
@@ -9,7 +9,6 @@ from fastapi.routing import APIRoute
load_dotenv()
import io
-import os
import time
# this file is to test litellm/proxy
diff --git a/tests/logging_callback_tests/test_token_counting.py b/tests/logging_callback_tests/test_token_counting.py
index 69200f113db..e2160076b00 100644
--- a/tests/logging_callback_tests/test_token_counting.py
+++ b/tests/logging_callback_tests/test_token_counting.py
@@ -9,7 +9,6 @@ from fastapi.routing import APIRoute
load_dotenv()
import io
-import os
import time
import json
diff --git a/tests/logging_callback_tests/test_unit_test_litellm_logging.py b/tests/logging_callback_tests/test_unit_test_litellm_logging.py
index e01c09951d6..f82813b7475 100644
--- a/tests/logging_callback_tests/test_unit_test_litellm_logging.py
+++ b/tests/logging_callback_tests/test_unit_test_litellm_logging.py
@@ -19,8 +19,6 @@ from litellm._service_logger import ServiceLogging
import asyncio
-from litellm.litellm_core_utils.litellm_logging import Logging
-import litellm
service_logger = ServiceLogging()
diff --git a/tests/logging_callback_tests/test_view_request_resp_logs.py b/tests/logging_callback_tests/test_view_request_resp_logs.py
index ea778a44e67..37b65855774 100644
--- a/tests/logging_callback_tests/test_view_request_resp_logs.py
+++ b/tests/logging_callback_tests/test_view_request_resp_logs.py
@@ -10,9 +10,7 @@ import logging
import tempfile
from litellm._uuid import uuid
-import json
from datetime import datetime, timedelta, timezone
-from datetime import datetime
import pytest
diff --git a/tests/mcp_tests/conftest.py b/tests/mcp_tests/conftest.py
index 01d5f69974e..a3b425f72c3 100644
--- a/tests/mcp_tests/conftest.py
+++ b/tests/mcp_tests/conftest.py
@@ -33,7 +33,6 @@ def setup_and_teardown():
0, os.path.abspath("../..")
) # Adds the project directory to the system path
- import litellm
from litellm import Router
importlib.reload(litellm)
diff --git a/tests/mcp_tests/test_mcp_litellm_client.py b/tests/mcp_tests/test_mcp_litellm_client.py
index 01b0c217573..e197673ab10 100644
--- a/tests/mcp_tests/test_mcp_litellm_client.py
+++ b/tests/mcp_tests/test_mcp_litellm_client.py
@@ -13,7 +13,6 @@ from mcp.client.stdio import stdio_client
import os
from litellm import experimental_mcp_client
import litellm
-import pytest
import json
diff --git a/tests/openai_endpoints_tests/test_openai_batches_endpoint.py b/tests/openai_endpoints_tests/test_openai_batches_endpoint.py
index db8f75cf640..b6209853d82 100644
--- a/tests/openai_endpoints_tests/test_openai_batches_endpoint.py
+++ b/tests/openai_endpoints_tests/test_openai_batches_endpoint.py
@@ -15,7 +15,6 @@ from unittest.mock import patch, MagicMock, AsyncMock
BASE_URL = "http://localhost:4000" # Replace with your actual base URL
API_KEY = "sk-1234" # Replace with your actual API key
-from openai import OpenAI
client = OpenAI(base_url=BASE_URL, api_key=API_KEY)
diff --git a/tests/pass_through_unit_tests/test_assemblyai_unit_tests_passthrough.py b/tests/pass_through_unit_tests/test_assemblyai_unit_tests_passthrough.py
index 67bc4423d8c..6fdd4cc0f24 100644
--- a/tests/pass_through_unit_tests/test_assemblyai_unit_tests_passthrough.py
+++ b/tests/pass_through_unit_tests/test_assemblyai_unit_tests_passthrough.py
@@ -15,20 +15,13 @@ import litellm
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
-import json
import os
import sys
-from datetime import datetime
-from unittest.mock import AsyncMock, Mock, patch
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system-path
-import httpx
-import pytest
-import litellm
-from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
from litellm.proxy.pass_through_endpoints.llm_provider_handlers.assembly_passthrough_logging_handler import (
AssemblyAIPassthroughLoggingHandler,
AssemblyAITranscriptResponse,
diff --git a/tests/pass_through_unit_tests/test_unit_test_passthrough_router.py b/tests/pass_through_unit_tests/test_unit_test_passthrough_router.py
index b133cc2d862..ee1f8772568 100644
--- a/tests/pass_through_unit_tests/test_unit_test_passthrough_router.py
+++ b/tests/pass_through_unit_tests/test_unit_test_passthrough_router.py
@@ -7,7 +7,6 @@ from unittest.mock import AsyncMock, Mock, patch, MagicMock
sys.path.insert(0, os.path.abspath("../..")) #
import unittest
-from unittest.mock import patch
from litellm.proxy.pass_through_endpoints.passthrough_endpoint_router import (
PassthroughEndpointRouter,
)
diff --git a/tests/pass_through_unit_tests/test_vertex_ai_live_passthrough.py b/tests/pass_through_unit_tests/test_vertex_ai_live_passthrough.py
index 9e9dd3cbe05..f25d9e7c1d3 100644
--- a/tests/pass_through_unit_tests/test_vertex_ai_live_passthrough.py
+++ b/tests/pass_through_unit_tests/test_vertex_ai_live_passthrough.py
@@ -440,9 +440,6 @@ class TestVertexAILivePassthroughIntegration:
def test_vertex_ai_live_route_detection(self):
"""Test that the route detection works correctly"""
- from litellm.proxy.pass_through_endpoints.success_handler import (
- PassThroughEndpointLogging,
- )
handler = PassThroughEndpointLogging()
@@ -464,9 +461,6 @@ class TestVertexAILivePassthroughIntegration:
self, mock_handler_class, mock_logging_obj
):
"""Test the success handler integration with Vertex AI Live"""
- from litellm.proxy.pass_through_endpoints.success_handler import (
- PassThroughEndpointLogging,
- )
# Mock the handler
mock_handler = MagicMock()
diff --git a/tests/proxy_admin_ui_tests/conftest.py b/tests/proxy_admin_ui_tests/conftest.py
index eca0bc431a5..67365f4745d 100644
--- a/tests/proxy_admin_ui_tests/conftest.py
+++ b/tests/proxy_admin_ui_tests/conftest.py
@@ -22,7 +22,6 @@ def setup_and_teardown():
0, os.path.abspath("../..")
) # Adds the project directory to the system path
- import litellm
from litellm import Router
importlib.reload(litellm)
diff --git a/tests/proxy_admin_ui_tests/test_key_management.py b/tests/proxy_admin_ui_tests/test_key_management.py
index 7e8494b77fc..dec7404b3cf 100644
--- a/tests/proxy_admin_ui_tests/test_key_management.py
+++ b/tests/proxy_admin_ui_tests/test_key_management.py
@@ -12,7 +12,6 @@ from unittest.mock import MagicMock, patch
load_dotenv()
import io
-import os
import time
# this file is to test litellm/proxy
@@ -893,9 +892,6 @@ async def test_key_update_with_model_specific_params(prisma_client):
setattr(litellm.proxy.proxy_server, "master_key", "sk-1234")
await litellm.proxy.proxy_server.prisma_client.connect()
- from litellm.proxy.management_endpoints.key_management_endpoints import (
- update_key_fn,
- )
from litellm.proxy._types import UpdateKeyRequest
new_key = await generate_key_fn(
diff --git a/tests/proxy_admin_ui_tests/test_role_based_access.py b/tests/proxy_admin_ui_tests/test_role_based_access.py
index f9506fb694b..587a1048595 100644
--- a/tests/proxy_admin_ui_tests/test_role_based_access.py
+++ b/tests/proxy_admin_ui_tests/test_role_based_access.py
@@ -14,7 +14,6 @@ from fastapi.routing import APIRoute
load_dotenv()
import io
-import os
import time
# this file is to test litellm/proxy
@@ -77,7 +76,6 @@ from litellm.proxy.utils import PrismaClient, ProxyLogging, hash_token, update_s
verbose_proxy_logger.setLevel(level=logging.DEBUG)
-from starlette.datastructures import URL
from litellm.caching.caching import DualCache
from litellm.proxy._types import *
diff --git a/tests/proxy_admin_ui_tests/test_route_check_unit_tests.py b/tests/proxy_admin_ui_tests/test_route_check_unit_tests.py
index f0cc6985e66..6396a92cf80 100644
--- a/tests/proxy_admin_ui_tests/test_route_check_unit_tests.py
+++ b/tests/proxy_admin_ui_tests/test_route_check_unit_tests.py
@@ -11,7 +11,6 @@ from fastapi.routing import APIRoute
load_dotenv()
import io
-import os
import time
@@ -23,7 +22,7 @@ sys.path.insert(
import asyncio
import logging
-from fastapi import HTTPException, Request
+from fastapi import HTTPException
import pytest
from litellm.proxy.auth.route_checks import RouteChecks
from litellm.proxy._types import LiteLLM_UserTable, LitellmUserRoles, UserAPIKeyAuth
diff --git a/tests/proxy_admin_ui_tests/test_usage_endpoints.py b/tests/proxy_admin_ui_tests/test_usage_endpoints.py
index 54ad136f082..0d1fa3afa0c 100644
--- a/tests/proxy_admin_ui_tests/test_usage_endpoints.py
+++ b/tests/proxy_admin_ui_tests/test_usage_endpoints.py
@@ -25,7 +25,6 @@ from fastapi.routing import APIRoute
load_dotenv()
import io
-import os
import time
# this file is to test litellm/proxy
diff --git a/tests/proxy_unit_tests/test_aproxy_startup.py b/tests/proxy_unit_tests/test_aproxy_startup.py
index 4dbf5b462a9..324a881a7c3 100644
--- a/tests/proxy_unit_tests/test_aproxy_startup.py
+++ b/tests/proxy_unit_tests/test_aproxy_startup.py
@@ -5,7 +5,7 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
-import os, io
+import io
# this file is to test litellm/proxy
diff --git a/tests/proxy_unit_tests/test_audit_logs_proxy.py b/tests/proxy_unit_tests/test_audit_logs_proxy.py
index 9e2b69176ec..a5332213886 100644
--- a/tests/proxy_unit_tests/test_audit_logs_proxy.py
+++ b/tests/proxy_unit_tests/test_audit_logs_proxy.py
@@ -10,7 +10,6 @@ from fastapi.routing import APIRoute
import io
-import os
import time
# this file is to test litellm/proxy
@@ -24,7 +23,6 @@ import logging
load_dotenv()
import pytest
-from litellm._uuid import uuid
import litellm
from litellm._logging import verbose_proxy_logger
diff --git a/tests/proxy_unit_tests/test_auth_checks.py b/tests/proxy_unit_tests/test_auth_checks.py
index ef3cbd0ae95..947117bd882 100644
--- a/tests/proxy_unit_tests/test_auth_checks.py
+++ b/tests/proxy_unit_tests/test_auth_checks.py
@@ -6,7 +6,6 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
-import os
sys.path.insert(
0, os.path.abspath("../..")
@@ -478,7 +477,6 @@ async def test_virtual_key_max_budget_check(
2. Raises BudgetExceededError when spend >= max_budget
"""
from litellm.proxy.auth.auth_checks import _virtual_key_max_budget_check
- from litellm.proxy.utils import ProxyLogging
# Setup test data
valid_token = UserAPIKeyAuth(
@@ -836,7 +834,6 @@ async def test_can_user_call_model_with_no_default_models():
@pytest.mark.asyncio
async def test_get_fuzzy_user_object():
from litellm.proxy.auth.auth_checks import _get_fuzzy_user_object
- from litellm.proxy.utils import PrismaClient
from unittest.mock import AsyncMock, MagicMock
# Setup mock Prisma client
diff --git a/tests/proxy_unit_tests/test_banned_keyword_list.py b/tests/proxy_unit_tests/test_banned_keyword_list.py
index 90066b74f61..acf4bdbb8e0 100644
--- a/tests/proxy_unit_tests/test_banned_keyword_list.py
+++ b/tests/proxy_unit_tests/test_banned_keyword_list.py
@@ -8,7 +8,6 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/proxy_unit_tests/test_e2e_pod_lock_manager.py b/tests/proxy_unit_tests/test_e2e_pod_lock_manager.py
index fd21fbb6742..b1e5fd29cde 100644
--- a/tests/proxy_unit_tests/test_e2e_pod_lock_manager.py
+++ b/tests/proxy_unit_tests/test_e2e_pod_lock_manager.py
@@ -14,7 +14,6 @@ from unittest.mock import MagicMock, patch
load_dotenv()
import io
-import os
import time
import fakeredis
diff --git a/tests/proxy_unit_tests/test_jwt.py b/tests/proxy_unit_tests/test_jwt.py
index 686d7021257..abd91113f96 100644
--- a/tests/proxy_unit_tests/test_jwt.py
+++ b/tests/proxy_unit_tests/test_jwt.py
@@ -14,7 +14,6 @@ from litellm._uuid import uuid
from dotenv import load_dotenv
load_dotenv()
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/proxy_unit_tests/test_key_generate_prisma.py b/tests/proxy_unit_tests/test_key_generate_prisma.py
index 6a568d94f8c..c845fb35774 100644
--- a/tests/proxy_unit_tests/test_key_generate_prisma.py
+++ b/tests/proxy_unit_tests/test_key_generate_prisma.py
@@ -33,7 +33,6 @@ import httpx
load_dotenv()
import io
-import os
import time
# this file is to test litellm/proxy
diff --git a/tests/proxy_unit_tests/test_proxy_config_unit_test.py b/tests/proxy_unit_tests/test_proxy_config_unit_test.py
index 99b0dc4fd13..a567ad2b025 100644
--- a/tests/proxy_unit_tests/test_proxy_config_unit_test.py
+++ b/tests/proxy_unit_tests/test_proxy_config_unit_test.py
@@ -11,7 +11,6 @@ import litellm.proxy.proxy_server
load_dotenv()
import io
-import os
# this file is to test litellm/proxy
diff --git a/tests/proxy_unit_tests/test_proxy_custom_auth.py b/tests/proxy_unit_tests/test_proxy_custom_auth.py
index cffcc2e7f2c..c5b6c1e6209 100644
--- a/tests/proxy_unit_tests/test_proxy_custom_auth.py
+++ b/tests/proxy_unit_tests/test_proxy_custom_auth.py
@@ -6,7 +6,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
-import os
# this file is to test litellm/proxy
diff --git a/tests/proxy_unit_tests/test_proxy_custom_logger.py b/tests/proxy_unit_tests/test_proxy_custom_logger.py
index cfcbf61433e..20b9678c7fa 100644
--- a/tests/proxy_unit_tests/test_proxy_custom_logger.py
+++ b/tests/proxy_unit_tests/test_proxy_custom_logger.py
@@ -3,7 +3,7 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
-import os, io, asyncio
+import io, asyncio
# this file is to test litellm/proxy
diff --git a/tests/proxy_unit_tests/test_proxy_encrypt_decrypt.py b/tests/proxy_unit_tests/test_proxy_encrypt_decrypt.py
index ab84d21479f..396a34e9b85 100644
--- a/tests/proxy_unit_tests/test_proxy_encrypt_decrypt.py
+++ b/tests/proxy_unit_tests/test_proxy_encrypt_decrypt.py
@@ -6,7 +6,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/proxy_unit_tests/test_proxy_exception_mapping.py b/tests/proxy_unit_tests/test_proxy_exception_mapping.py
index 2487c69d9d3..e9884f8b269 100644
--- a/tests/proxy_unit_tests/test_proxy_exception_mapping.py
+++ b/tests/proxy_unit_tests/test_proxy_exception_mapping.py
@@ -10,7 +10,6 @@ from dotenv import load_dotenv
load_dotenv()
import asyncio
import io
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/proxy_unit_tests/test_proxy_pass_user_config.py b/tests/proxy_unit_tests/test_proxy_pass_user_config.py
index 6beb86eca72..73998253f32 100644
--- a/tests/proxy_unit_tests/test_proxy_pass_user_config.py
+++ b/tests/proxy_unit_tests/test_proxy_pass_user_config.py
@@ -3,7 +3,7 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
-import os, io
+import io
# this file is to test litellm/proxy
diff --git a/tests/proxy_unit_tests/test_proxy_reject_logging.py b/tests/proxy_unit_tests/test_proxy_reject_logging.py
index e0b575f4a71..440f2362276 100644
--- a/tests/proxy_unit_tests/test_proxy_reject_logging.py
+++ b/tests/proxy_unit_tests/test_proxy_reject_logging.py
@@ -18,7 +18,6 @@ from datetime import datetime
from dotenv import load_dotenv
load_dotenv()
-import os
sys.path.insert(
0, os.path.abspath("../..")
@@ -45,7 +44,6 @@ from litellm.proxy.proxy_server import (
embeddings,
)
from litellm.proxy.utils import ProxyLogging, hash_token
-from litellm.router import Router
class testLogger(CustomLogger):
diff --git a/tests/proxy_unit_tests/test_proxy_routes.py b/tests/proxy_unit_tests/test_proxy_routes.py
index db41bd65409..9d9c02257c2 100644
--- a/tests/proxy_unit_tests/test_proxy_routes.py
+++ b/tests/proxy_unit_tests/test_proxy_routes.py
@@ -5,7 +5,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
-import os
# this file is to test litellm/proxy
diff --git a/tests/proxy_unit_tests/test_proxy_server.py b/tests/proxy_unit_tests/test_proxy_server.py
index 04bc80bf0d6..e8f0e6953bc 100644
--- a/tests/proxy_unit_tests/test_proxy_server.py
+++ b/tests/proxy_unit_tests/test_proxy_server.py
@@ -11,7 +11,6 @@ import litellm.proxy.proxy_server
load_dotenv()
import io
import json
-import os
# this file is to test litellm/proxy
@@ -872,7 +871,6 @@ def test_health(client_no_auth):
# test_add_new_model()
-from litellm.integrations.custom_logger import CustomLogger
class MyCustomHandler(CustomLogger):
@@ -1110,7 +1108,7 @@ async def test_get_team_redis(client_no_auth):
import random
from litellm._uuid import uuid
-from unittest.mock import AsyncMock, MagicMock, PropertyMock, patch
+from unittest.mock import PropertyMock
from litellm.proxy._types import (
LitellmUserRoles,
@@ -1138,7 +1136,7 @@ def mock_prisma_client():
)
@pytest.mark.asyncio
@pytest.mark.skip(reason="Requires reliable external DB connection (prisma).")
-async def test_create_user_default_budget(prisma_client, user_role):
+async def test_create_user_default_budget(prisma_client, user_role): # noqa: F811 # pytest fixture, not a redefinition
setattr(litellm.proxy.proxy_server, "prisma_client", prisma_client)
setattr(litellm.proxy.proxy_server, "master_key", "sk-1234")
@@ -1179,7 +1177,7 @@ async def test_create_user_default_budget(prisma_client, user_role):
@pytest.mark.parametrize("new_member_method", ["user_id", "user_email"])
@pytest.mark.asyncio
@pytest.mark.skip(reason="Requires reliable external DB connection (prisma).")
-async def test_create_team_member_add(prisma_client, new_member_method):
+async def test_create_team_member_add(prisma_client, new_member_method): # noqa: F811 # pytest fixture, not a redefinition
import time
from fastapi import Request
@@ -1291,7 +1289,7 @@ async def test_create_team_member_add(prisma_client, new_member_method):
@pytest.mark.parametrize("team_route", ["/team/member_add", "/team/member_delete"])
@pytest.mark.asyncio
async def test_create_team_member_add_team_admin_user_api_key_auth(
- prisma_client, team_member_role, team_route
+ prisma_client, team_member_role, team_route # noqa: F811 # pytest fixture, not a redefinition
):
import time
@@ -1353,7 +1351,7 @@ async def test_create_team_member_add_team_admin_user_api_key_auth(
@pytest.mark.parametrize("user_role", ["admin", "user"])
@pytest.mark.asyncio
async def test_create_team_member_add_team_admin(
- prisma_client, new_member_method, user_role
+ prisma_client, new_member_method, user_role # noqa: F811 # pytest fixture, not a redefinition
):
"""
Relevant issue - https://github.com/BerriAI/litellm/issues/5300
@@ -1495,7 +1493,7 @@ async def test_create_team_member_add_team_admin(
@pytest.mark.asyncio
@pytest.mark.skip(reason="Requires reliable external DB connection (prisma).")
-async def test_user_info_team_list(prisma_client):
+async def test_user_info_team_list(prisma_client): # noqa: F811 # pytest fixture, not a redefinition
"""Assert user_info for admin calls team_list function"""
from litellm.proxy._types import LiteLLM_UserTable
@@ -1535,7 +1533,7 @@ async def test_user_info_team_list(prisma_client):
@pytest.mark.skip(reason="Local test")
@pytest.mark.asyncio
-async def test_add_callback_via_key(prisma_client):
+async def test_add_callback_via_key(prisma_client): # noqa: F811 # pytest fixture, not a redefinition
"""
Test if callback specified in key, is used.
"""
@@ -2151,7 +2149,7 @@ async def test_model_info_alias_without_prisma(hidden):
@pytest.mark.parametrize("hidden", [True, False])
@pytest.mark.asyncio
@pytest.mark.skip(reason="Requires reliable external DB connection (prisma).")
-async def test_proxy_model_group_alias_checks(prisma_client, hidden):
+async def test_proxy_model_group_alias_checks(prisma_client, hidden): # noqa: F811 # pytest fixture, not a redefinition
"""
Check if model group alias is returned on
@@ -2232,7 +2230,7 @@ async def test_proxy_model_group_alias_checks(prisma_client, hidden):
@pytest.mark.asyncio
@pytest.mark.skip(reason="Requires reliable external DB connection (prisma).")
-async def test_proxy_model_group_info_rerank(prisma_client):
+async def test_proxy_model_group_info_rerank(prisma_client): # noqa: F811 # pytest fixture, not a redefinition
"""
Check if rerank model is returned on the following endpoints
@@ -3035,7 +3033,7 @@ async def test_update_config_success_callback_normalization():
setattr(proxy_server, "prisma_client", MockPrisma())
class MockProxyConfig:
- async def add_deployment(self, prisma_client=None, proxy_logging_obj=None):
+ async def add_deployment(self, prisma_client=None, proxy_logging_obj=None): # noqa: F811 # pytest fixture, not a redefinition
return None
setattr(proxy_server, "proxy_config", MockProxyConfig())
diff --git a/tests/proxy_unit_tests/test_proxy_setting_guardrails.py b/tests/proxy_unit_tests/test_proxy_setting_guardrails.py
index d5dac59b3cf..d16546249a4 100644
--- a/tests/proxy_unit_tests/test_proxy_setting_guardrails.py
+++ b/tests/proxy_unit_tests/test_proxy_setting_guardrails.py
@@ -8,7 +8,6 @@ from dotenv import load_dotenv
load_dotenv()
import asyncio
import io
-import os
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/proxy_unit_tests/test_unit_test_proxy_hooks.py b/tests/proxy_unit_tests/test_unit_test_proxy_hooks.py
index 8f17e34b94a..492b4803af4 100644
--- a/tests/proxy_unit_tests/test_unit_test_proxy_hooks.py
+++ b/tests/proxy_unit_tests/test_unit_test_proxy_hooks.py
@@ -17,7 +17,6 @@ async def test_disable_spend_logs():
Test that the spend logs are not written to the database when disable_spend_logs is True
"""
# Mock the necessary components
- import asyncio
mock_prisma_client = Mock()
mock_prisma_client.spend_log_transactions = []
diff --git a/tests/proxy_unit_tests/test_user_api_key_auth.py b/tests/proxy_unit_tests/test_user_api_key_auth.py
index 58dbe3ad370..eaff71a8f58 100644
--- a/tests/proxy_unit_tests/test_user_api_key_auth.py
+++ b/tests/proxy_unit_tests/test_user_api_key_auth.py
@@ -559,7 +559,6 @@ def test_get_api_key_from_custom_header_different_casing():
)
-from litellm.proxy._types import LitellmUserRoles
@pytest.mark.parametrize(
diff --git a/tests/router_unit_tests/conftest.py b/tests/router_unit_tests/conftest.py
index 6a8f3e589f4..db6a722a926 100644
--- a/tests/router_unit_tests/conftest.py
+++ b/tests/router_unit_tests/conftest.py
@@ -48,7 +48,6 @@ def setup_and_teardown():
0, os.path.abspath("../..")
) # Adds the project directory to the system path
- import litellm
from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER
diff --git a/tests/router_unit_tests/test_router_cooldown_utils.py b/tests/router_unit_tests/test_router_cooldown_utils.py
index 6bcb0d9bf84..a51b0dc21af 100644
--- a/tests/router_unit_tests/test_router_cooldown_utils.py
+++ b/tests/router_unit_tests/test_router_cooldown_utils.py
@@ -27,10 +27,6 @@ from litellm.router_utils.router_callbacks.track_deployment_metrics import (
increment_deployment_successes_for_current_minute,
)
-import pytest
-from unittest.mock import patch
-from litellm import Router
-from litellm.router_utils.cooldown_handlers import _should_cooldown_deployment
load_dotenv()
diff --git a/tests/router_unit_tests/test_router_index_management.py b/tests/router_unit_tests/test_router_index_management.py
index 983fc0c4c3b..3f0a185e8bf 100644
--- a/tests/router_unit_tests/test_router_index_management.py
+++ b/tests/router_unit_tests/test_router_index_management.py
@@ -2,7 +2,6 @@ import sys
import os
import pytest
import ast
-import ast
sys.path.insert(
0, os.path.abspath("../..")
diff --git a/tests/store_model_in_db_tests/test_callbacks_in_db.py b/tests/store_model_in_db_tests/test_callbacks_in_db.py
index e92aeb6ebc4..6497e4064b7 100644
--- a/tests/store_model_in_db_tests/test_callbacks_in_db.py
+++ b/tests/store_model_in_db_tests/test_callbacks_in_db.py
@@ -14,7 +14,6 @@ import aiohttp
import os
import dotenv
from dotenv import load_dotenv
-import pytest
from openai import AsyncOpenAI, APIConnectionError
from openai.types.chat import ChatCompletion
diff --git a/tests/store_model_in_db_tests/test_team_models.py b/tests/store_model_in_db_tests/test_team_models.py
index 83822433a63..b303dfcb7e6 100644
--- a/tests/store_model_in_db_tests/test_team_models.py
+++ b/tests/store_model_in_db_tests/test_team_models.py
@@ -5,7 +5,6 @@ import json
from openai import AsyncOpenAI
from litellm._uuid import uuid
from httpx import AsyncClient
-from litellm._uuid import uuid
import os
TEST_MASTER_KEY = "sk-1234"
diff --git a/tests/test_callbacks_on_proxy.py b/tests/test_callbacks_on_proxy.py
index 17c0db9260f..130ce773b1f 100644
--- a/tests/test_callbacks_on_proxy.py
+++ b/tests/test_callbacks_on_proxy.py
@@ -13,7 +13,6 @@ import re
import dotenv
from collections import Counter
from dotenv import load_dotenv
-import pytest
load_dotenv()
diff --git a/tests/test_fallbacks.py b/tests/test_fallbacks.py
index bc9aa4c64c8..7d6deaddd9e 100644
--- a/tests/test_fallbacks.py
+++ b/tests/test_fallbacks.py
@@ -289,10 +289,8 @@ async def test_chat_completion_client_fallbacks_with_custom_message(has_access):
pytest.fail("Expected this to work: {}".format(str(e)))
-import asyncio
from openai import AsyncOpenAI
from typing import List
-import time
async def make_request(client: AsyncOpenAI, model: str) -> bool:
diff --git a/tests/test_litellm/caching/test_caching_handler.py b/tests/test_litellm/caching/test_caching_handler.py
index 38019fc0fee..9684e82f550 100644
--- a/tests/test_litellm/caching/test_caching_handler.py
+++ b/tests/test_litellm/caching/test_caching_handler.py
@@ -14,7 +14,7 @@ sys.path.insert(
0, os.path.abspath("../../..")
) # Adds the parent directory to the system path
from datetime import datetime
-from unittest.mock import AsyncMock, MagicMock
+from unittest.mock import AsyncMock
from litellm.caching.caching_handler import LLMCachingHandler
diff --git a/tests/test_litellm/google_genai/test_google_genai_adapter.py b/tests/test_litellm/google_genai/test_google_genai_adapter.py
index f21564546a8..8f5f4d41f3c 100644
--- a/tests/test_litellm/google_genai/test_google_genai_adapter.py
+++ b/tests/test_litellm/google_genai/test_google_genai_adapter.py
@@ -15,11 +15,9 @@ sys.path.insert(
0, os.path.abspath("../../..")
) # Adds the parent directory to the system path
-import json
import os
import sys
-import pytest
import litellm
diff --git a/tests/test_litellm/google_genai/test_google_genai_main.py b/tests/test_litellm/google_genai/test_google_genai_main.py
index 8f56b4e4bc0..8441b62e559 100644
--- a/tests/test_litellm/google_genai/test_google_genai_main.py
+++ b/tests/test_litellm/google_genai/test_google_genai_main.py
@@ -13,11 +13,9 @@ sys.path.insert(
0, os.path.abspath("../../..")
) # Adds the parent directory to the system path
-import json
import os
import sys
-import pytest
import litellm
diff --git a/tests/test_litellm/integrations/test_galileo.py b/tests/test_litellm/integrations/test_galileo.py
index 0533b7ca7d1..8905795bbc6 100644
--- a/tests/test_litellm/integrations/test_galileo.py
+++ b/tests/test_litellm/integrations/test_galileo.py
@@ -112,7 +112,6 @@ def test_galileo_input_text_from_messages():
def test_galileo_get_output_str_responses_api(galileo_v2_env):
- from litellm.types.llms.openai import ResponsesAPIResponse
logger = GalileoObserve()
resp_dict = {
diff --git a/tests/test_litellm/integrations/test_langfuse.py b/tests/test_litellm/integrations/test_langfuse.py
index 3c7dd51bff8..73a62e5594d 100644
--- a/tests/test_litellm/integrations/test_langfuse.py
+++ b/tests/test_litellm/integrations/test_langfuse.py
@@ -14,7 +14,6 @@ from litellm.integrations.langfuse import langfuse as langfuse_module
from litellm.integrations.langfuse.langfuse import LangFuseLogger
sys.path.insert(0, os.path.abspath("../.."))
-from litellm.integrations.langfuse.langfuse import LangFuseLogger
# Import LangfuseUsageDetails directly from the module where it's defined
from litellm.types.integrations.langfuse import *
diff --git a/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py b/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py
index 08d8c17cc2e..a10dc46eb42 100644
--- a/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py
+++ b/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py
@@ -332,7 +332,6 @@ def test_bedrock_get_document_format_fallback_mimes():
This tests the fallback mechanism when mimetypes.guess_all_extensions returns empty results,
which can happen in Docker containers where mimetypes depends on OS-installed MIME types.
"""
- from unittest.mock import patch
# Test DOCX fallback
docx_mime = (
diff --git a/tests/test_litellm/litellm_core_utils/test_token_counter.py b/tests/test_litellm/litellm_core_utils/test_token_counter.py
index eec4b307c87..bd373f87eea 100644
--- a/tests/test_litellm/litellm_core_utils/test_token_counter.py
+++ b/tests/test_litellm/litellm_core_utils/test_token_counter.py
@@ -13,7 +13,7 @@ import tiktoken
sys.path.insert(
0, os.path.abspath("../../..")
) # Adds the parent directory to the system path
-from unittest.mock import AsyncMock, MagicMock, patch
+from unittest.mock import AsyncMock, patch
import litellm
from litellm import create_pretrained_tokenizer, decode, encode, get_modified_max_tokens
@@ -634,7 +634,6 @@ def test_token_counter():
import unittest
-from unittest.mock import MagicMock, patch
from litellm.utils import _select_tokenizer_helper, claude_json_str, encoding
diff --git a/tests/test_litellm/llms/anthropic/batches/test_transformation.py b/tests/test_litellm/llms/anthropic/batches/test_transformation.py
index 4a2adb01ea5..1635abcefd8 100644
--- a/tests/test_litellm/llms/anthropic/batches/test_transformation.py
+++ b/tests/test_litellm/llms/anthropic/batches/test_transformation.py
@@ -619,7 +619,6 @@ def test_transform_response_reraises_unexpected_error(config):
# automatically. See base_batches_config_test.py.
# --------------------------------------------------------------------------- #
-from litellm.types.utils import LlmProviders # noqa: E402
from tests.test_litellm.llms.base_llm.batches.base_batches_config_test import ( # noqa: E402
BatchesConfigContractTests,
)
diff --git a/tests/test_litellm/llms/azure/image_generation/test_azure_image_generation_init.py b/tests/test_litellm/llms/azure/image_generation/test_azure_image_generation_init.py
index a211a69b9c7..857ed9d22a6 100644
--- a/tests/test_litellm/llms/azure/image_generation/test_azure_image_generation_init.py
+++ b/tests/test_litellm/llms/azure/image_generation/test_azure_image_generation_init.py
@@ -312,7 +312,6 @@ def test_azure_image_generation_base_model_vs_deployment_name():
model: azure/gpt-image-15 # deployment name (URL only)
base_model: gpt-image-1.5 # optional, for LiteLLM metadata
"""
- from unittest.mock import MagicMock
# Setup test parameters
azure_chat_completion = AzureChatCompletion()
@@ -385,7 +384,6 @@ async def test_azure_aimage_generation_base_model_vs_deployment_name():
Async variant of test_azure_image_generation_base_model_vs_deployment_name:
deployment in URL, no ``model`` in the JSON body sent to Azure.
"""
- from unittest.mock import MagicMock
# Setup test parameters
azure_chat_completion = AzureChatCompletion()
diff --git a/tests/test_litellm/llms/fireworks_ai/completion/test_fireworks_ai_text_completion_transformation.py b/tests/test_litellm/llms/fireworks_ai/completion/test_fireworks_ai_text_completion_transformation.py
index 9fe76d142ce..4f76a39684a 100644
--- a/tests/test_litellm/llms/fireworks_ai/completion/test_fireworks_ai_text_completion_transformation.py
+++ b/tests/test_litellm/llms/fireworks_ai/completion/test_fireworks_ai_text_completion_transformation.py
@@ -18,7 +18,6 @@ from litellm.llms.fireworks_ai.completion.transformation import (
def force_local_model_cost(monkeypatch):
"""Force local model cost map usage for all tests in this file."""
monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True")
- import litellm
from litellm.litellm_core_utils.get_model_cost_map import get_model_cost_map
litellm.model_cost = get_model_cost_map(url=litellm.model_cost_map_url)
diff --git a/tests/test_litellm/llms/github_copilot/test_github_copilot_transformation.py b/tests/test_litellm/llms/github_copilot/test_github_copilot_transformation.py
index 52f1a6a99b8..51cffd5e51a 100644
--- a/tests/test_litellm/llms/github_copilot/test_github_copilot_transformation.py
+++ b/tests/test_litellm/llms/github_copilot/test_github_copilot_transformation.py
@@ -11,7 +11,6 @@ import pytest
sys.path.insert(0, os.path.abspath("../.."))
import httpx
-import pytest
from respx import MockRouter
import litellm
diff --git a/tests/test_litellm/llms/ollama/test_ollama_chat_transformation.py b/tests/test_litellm/llms/ollama/test_ollama_chat_transformation.py
index 906c51d8064..8f3dbf7b0d9 100644
--- a/tests/test_litellm/llms/ollama/test_ollama_chat_transformation.py
+++ b/tests/test_litellm/llms/ollama/test_ollama_chat_transformation.py
@@ -86,7 +86,6 @@ class TestOllamaChatConfigResponseFormat:
def test_transform_request_loads_config_parameters(self):
"""Test that transform_request loads config parameters without overriding existing optional_params"""
# Set config parameters on the class
- import litellm
litellm.OllamaChatConfig(num_ctx=8000, temperature=0.0)
@@ -383,7 +382,6 @@ class TestOllamaToolCalling:
import json
from unittest.mock import MagicMock
- import litellm
from litellm.types.utils import Choices, Message, ModelResponse
config = OllamaChatConfig()
diff --git a/tests/test_litellm/llms/openai/chat/test_openai_gpt_transformation.py b/tests/test_litellm/llms/openai/chat/test_openai_gpt_transformation.py
index 45f1bdbfa85..101c5363bf7 100644
--- a/tests/test_litellm/llms/openai/chat/test_openai_gpt_transformation.py
+++ b/tests/test_litellm/llms/openai/chat/test_openai_gpt_transformation.py
@@ -16,7 +16,6 @@ from litellm.llms.openai.chat.gpt_transformation import (
OpenAIChatCompletionStreamingHandler,
OpenAIGPTConfig,
)
-from litellm.llms.openai.chat.gpt_5_transformation import OpenAIGPT5Config
class TestOpenAIGPTConfig:
diff --git a/tests/test_litellm/llms/openai/realtime/test_openai_realtime_handler.py b/tests/test_litellm/llms/openai/realtime/test_openai_realtime_handler.py
index e9798f45dce..2633e76b0f3 100644
--- a/tests/test_litellm/llms/openai/realtime/test_openai_realtime_handler.py
+++ b/tests/test_litellm/llms/openai/realtime/test_openai_realtime_handler.py
@@ -97,7 +97,6 @@ def test_openai_realtime_handler_model_parameter_inclusion():
import asyncio
-from unittest.mock import AsyncMock, MagicMock, patch
import pytest
diff --git a/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py b/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py
index b7265ed62e9..3d882deeb52 100644
--- a/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py
+++ b/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py
@@ -5273,7 +5273,6 @@ class TestModelResponseIteratorCleanup:
return obj
def test_aclose_closes_iterator_and_response(self):
- import asyncio
from unittest.mock import AsyncMock, MagicMock
from litellm.llms.vertex_ai.gemini.vertex_and_google_ai_studio_gemini import (
@@ -5323,7 +5322,6 @@ class TestModelResponseIteratorCleanup:
mock_response.close.assert_called_once()
def test_aclose_without_response_does_not_raise(self):
- import asyncio
from unittest.mock import AsyncMock, MagicMock
from litellm.llms.vertex_ai.gemini.vertex_and_google_ai_studio_gemini import (
@@ -5345,7 +5343,6 @@ class TestModelResponseIteratorCleanup:
mock_iterator.aclose.assert_awaited_once()
def test_aclose_tolerates_iterator_error(self):
- import asyncio
from unittest.mock import AsyncMock, MagicMock
from litellm.llms.vertex_ai.gemini.vertex_and_google_ai_studio_gemini import (
@@ -5372,7 +5369,6 @@ class TestModelResponseIteratorCleanup:
def test_custom_stream_wrapper_aclose_triggers_model_response_iterator_aclose(self):
"""CustomStreamWrapper.aclose() must propagate to ModelResponseIterator.aclose()."""
- import asyncio
from unittest.mock import AsyncMock, MagicMock
from litellm.litellm_core_utils.streaming_handler import CustomStreamWrapper
diff --git a/tests/test_litellm/llms/watsonx/test_watsonx_common_utils.py b/tests/test_litellm/llms/watsonx/test_watsonx_common_utils.py
index 8b7a297ec67..be74dc40eda 100644
--- a/tests/test_litellm/llms/watsonx/test_watsonx_common_utils.py
+++ b/tests/test_litellm/llms/watsonx/test_watsonx_common_utils.py
@@ -41,9 +41,9 @@ class TestGenerateIAMToken:
# Verify get_secret_str was called with correct keys in order
# Note: get_watsonx_iam_url() also calls get_secret_str("WATSONX_IAM_URL")
calls = [
- call[0][0]
- for call in mock_get_secret_str.call_args_list
- if call[0][0] != "WATSONX_IAM_URL"
+ recorded[0][0]
+ for recorded in mock_get_secret_str.call_args_list
+ if recorded[0][0] != "WATSONX_IAM_URL"
]
assert "WX_API_KEY" in calls
assert "WATSONX_API_KEY" in calls
@@ -155,9 +155,9 @@ class TestGenerateIAMToken:
# Verify get_secret_str was called with expected keys (checking short-circuit behavior)
# Note: get_watsonx_iam_url() also calls get_secret_str("WATSONX_IAM_URL"), so we filter that out
actual_calls = [
- call[0][0]
- for call in mock_get_secret_str.call_args_list
- if call[0][0] != "WATSONX_IAM_URL"
+ recorded[0][0]
+ for recorded in mock_get_secret_str.call_args_list
+ if recorded[0][0] != "WATSONX_IAM_URL"
]
assert (
actual_calls == expected_calls
@@ -189,9 +189,9 @@ class TestGenerateIAMToken:
# Verify get_secret_str was NOT called for API keys (since api_key was provided)
# Note: get_watsonx_iam_url() calls get_secret_str("WATSONX_IAM_URL"), which is expected
api_key_calls = [
- call[0][0]
- for call in mock_get_secret_str.call_args_list
- if call[0][0] not in ["WATSONX_IAM_URL"]
+ recorded[0][0]
+ for recorded in mock_get_secret_str.call_args_list
+ if recorded[0][0] not in ["WATSONX_IAM_URL"]
]
assert (
len(api_key_calls) == 0
@@ -219,9 +219,9 @@ class TestGenerateIAMToken:
# Verify get_secret_str was called for all possible API keys
# Note: get_watsonx_iam_url() also calls get_secret_str("WATSONX_IAM_URL")
calls = [
- call[0][0]
- for call in mock_get_secret_str.call_args_list
- if call[0][0] != "WATSONX_IAM_URL"
+ recorded[0][0]
+ for recorded in mock_get_secret_str.call_args_list
+ if recorded[0][0] != "WATSONX_IAM_URL"
]
assert "WX_API_KEY" in calls
assert "WATSONX_API_KEY" in calls
diff --git a/tests/test_litellm/passthrough/test_passthrough_main.py b/tests/test_litellm/passthrough/test_passthrough_main.py
index 965f9fd8f7d..e43e4be8bcc 100644
--- a/tests/test_litellm/passthrough/test_passthrough_main.py
+++ b/tests/test_litellm/passthrough/test_passthrough_main.py
@@ -14,7 +14,6 @@ sys.path.insert(
) # Adds the parent directory to the system path
-from unittest.mock import MagicMock, patch
import litellm
from litellm.passthrough.main import allm_passthrough_route, llm_passthrough_route
diff --git a/tests/test_litellm/proxy/auth/test_model_checks.py b/tests/test_litellm/proxy/auth/test_model_checks.py
index 5161554b969..62073f4bf51 100644
--- a/tests/test_litellm/proxy/auth/test_model_checks.py
+++ b/tests/test_litellm/proxy/auth/test_model_checks.py
@@ -700,7 +700,6 @@ def test_expand_wildcard_deployments_non_wildcard_passthrough():
def test_expand_wildcard_deployments_openai_wildcard():
"""openai/* should expand into ≥1 known openai model entries."""
- from unittest.mock import patch
from litellm.proxy.auth.model_checks import (
expand_wildcard_deployments_for_model_info,
diff --git a/tests/test_litellm/proxy/auth/test_route_checks.py b/tests/test_litellm/proxy/auth/test_route_checks.py
index 636c5480d67..b3b73723726 100644
--- a/tests/test_litellm/proxy/auth/test_route_checks.py
+++ b/tests/test_litellm/proxy/auth/test_route_checks.py
@@ -1791,7 +1791,6 @@ def test_proxy_admin_viewer_can_access_global_spend_tags():
# Routes returning proxy-wide spend across every team / customer / api_key.
# Sourced from `LiteLLMRoutes.global_spend_tracking_routes` so any future
# additions to that list are exercised by these tests automatically.
-from litellm.proxy._types import LiteLLMRoutes
GLOBAL_SPEND_ROUTES = LiteLLMRoutes.global_spend_tracking_routes.value
@@ -2617,10 +2616,7 @@ def test_available_roles_accessible_to_non_admin_users(user_role):
# ── _user_is_org_admin tests ──────────────────────────────────────────────────
-from datetime import datetime
-from litellm.proxy._types import LiteLLM_OrganizationMembershipTable
-from litellm.proxy.auth.auth_checks_organization import _user_is_org_admin
def _make_org_admin_user(org_id: str) -> LiteLLM_UserTable:
diff --git a/tests/test_litellm/proxy/client/cli/test_keys_commands.py b/tests/test_litellm/proxy/client/cli/test_keys_commands.py
index 977aec9f5b7..5d88b031eac 100644
--- a/tests/test_litellm/proxy/client/cli/test_keys_commands.py
+++ b/tests/test_litellm/proxy/client/cli/test_keys_commands.py
@@ -124,7 +124,6 @@ def test_async_keys_generate_error_handling(mock_keys_client, cli_runner):
def test_async_keys_delete_error_handling(mock_keys_client, cli_runner):
- import requests
# Mock a connection error that would normally happen in CI
mock_keys_client.return_value.delete.side_effect = (
@@ -146,7 +145,6 @@ def test_async_keys_delete_error_handling(mock_keys_client, cli_runner):
def test_async_keys_delete_http_error_handling(mock_keys_client, cli_runner):
from unittest.mock import Mock
- import requests
# Create a mock response object for HTTPError
mock_response = Mock()
diff --git a/tests/test_litellm/proxy/db/test_db_spend_update_writer.py b/tests/test_litellm/proxy/db/test_db_spend_update_writer.py
index f3c2ca65d02..4113d708196 100644
--- a/tests/test_litellm/proxy/db/test_db_spend_update_writer.py
+++ b/tests/test_litellm/proxy/db/test_db_spend_update_writer.py
@@ -197,7 +197,7 @@ def test_enqueue_tool_registry_upsert_reads_every_choice():
db_writer._enqueue_tool_registry_upsert(kwargs={}, completion_response=response)
- enqueued = [call.args[0]["tool_name"] for call in db_writer.tool_discovery_queue.add_update.call_args_list]
+ enqueued = [c.args[0]["tool_name"] for c in db_writer.tool_discovery_queue.add_update.call_args_list]
assert enqueued == ["tool_alpha", "tool_beta"]
diff --git a/tests/test_litellm/proxy/db/test_exception_handler.py b/tests/test_litellm/proxy/db/test_exception_handler.py
index 84a9ddfacff..a656d5edcbc 100644
--- a/tests/test_litellm/proxy/db/test_exception_handler.py
+++ b/tests/test_litellm/proxy/db/test_exception_handler.py
@@ -6,7 +6,7 @@ from unittest.mock import MagicMock, patch
import httpx
import pytest
-from fastapi import HTTPException, Request, status
+from fastapi import HTTPException, Request
from prisma import errors as prisma_errors
from prisma.errors import (
ClientNotConnectedError,
diff --git a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_model_armor.py b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_model_armor.py
index 14c0d2f9435..613cbbce8b4 100644
--- a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_model_armor.py
+++ b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_model_armor.py
@@ -1964,7 +1964,6 @@ async def test_model_armor_guardrail_status_intervened_vs_failed():
def mock_open(read_data=""):
"""Helper to create a mock file object"""
- import io
from unittest.mock import MagicMock
file_object = io.StringIO(read_data)
diff --git a/tests/test_litellm/proxy/guardrails/test_qostodian_nexus_guardrail.py b/tests/test_litellm/proxy/guardrails/test_qostodian_nexus_guardrail.py
index 6daa3e1430d..2753d8dd134 100644
--- a/tests/test_litellm/proxy/guardrails/test_qostodian_nexus_guardrail.py
+++ b/tests/test_litellm/proxy/guardrails/test_qostodian_nexus_guardrail.py
@@ -16,7 +16,6 @@ from unittest.mock import MagicMock
def test_qostodian_nexus_initialization_with_defaults():
"""Test QostodianNexus initializes with default values."""
- import os
from unittest.mock import patch
from litellm.proxy.guardrails.guardrail_hooks.qohash import QostodianNexus
@@ -171,7 +170,6 @@ def test_qostodian_nexus_get_config_model():
def test_qostodian_nexus_env_vars():
"""Test that QOSTODIAN_NEXUS_API_BASE env var is picked up correctly."""
- import os
from unittest.mock import patch
from litellm.proxy.guardrails.guardrail_hooks.qohash import QostodianNexus
diff --git a/tests/test_litellm/proxy/health_endpoints/test_health_endpoints.py b/tests/test_litellm/proxy/health_endpoints/test_health_endpoints.py
index 831f659051c..e576ba87e88 100644
--- a/tests/test_litellm/proxy/health_endpoints/test_health_endpoints.py
+++ b/tests/test_litellm/proxy/health_endpoints/test_health_endpoints.py
@@ -1321,7 +1321,6 @@ def test_get_callback_identifier_string_and_object_with_callback_name():
- Object with callback_name attribute
- Object with empty/None callback_name (should fall through to other checks)
"""
- from litellm.proxy.health_endpoints._health_endpoints import get_callback_identifier
# Test 1: String callback should be returned as-is
assert get_callback_identifier("datadog") == "datadog"
@@ -1353,7 +1352,6 @@ def test_get_callback_identifier_custom_logger_registry_and_fallback():
- Object with callback_name that matches registry entry
- Fallback to callback_name() helper function
"""
- from litellm.proxy.health_endpoints._health_endpoints import get_callback_identifier
from litellm.litellm_core_utils.custom_logger_registry import CustomLoggerRegistry
# Test 1: Object registered in CustomLoggerRegistry (without callback_name attribute)
diff --git a/tests/test_litellm/proxy/hooks/test_parallel_request_limiter_v3.py b/tests/test_litellm/proxy/hooks/test_parallel_request_limiter_v3.py
index fee892ad342..a72871310c7 100644
--- a/tests/test_litellm/proxy/hooks/test_parallel_request_limiter_v3.py
+++ b/tests/test_litellm/proxy/hooks/test_parallel_request_limiter_v3.py
@@ -1575,7 +1575,6 @@ async def test_async_increment_tokens_with_ttl_preservation():
3. Second call: Increment same keys
4. Verify TTL decreased but wasn't reset to 60s
"""
- import os
import time
from litellm.caching.redis_cache import RedisCache
diff --git a/tests/test_litellm/proxy/management_endpoints/scim/test_scim_v2_endpoints.py b/tests/test_litellm/proxy/management_endpoints/scim/test_scim_v2_endpoints.py
index 0a9efd40b48..5f6c1a2375b 100644
--- a/tests/test_litellm/proxy/management_endpoints/scim/test_scim_v2_endpoints.py
+++ b/tests/test_litellm/proxy/management_endpoints/scim/test_scim_v2_endpoints.py
@@ -58,7 +58,6 @@ from litellm.types.proxy.management_endpoints.scim_v2 import (
SCIMUserGroup,
SCIMUserName,
)
-from litellm.proxy._types import ProxyException
@pytest.mark.asyncio
diff --git a/tests/test_litellm/proxy/management_endpoints/test_auto_router_endpoints.py b/tests/test_litellm/proxy/management_endpoints/test_auto_router_endpoints.py
index 6165e869989..5c61f8c557c 100644
--- a/tests/test_litellm/proxy/management_endpoints/test_auto_router_endpoints.py
+++ b/tests/test_litellm/proxy/management_endpoints/test_auto_router_endpoints.py
@@ -482,7 +482,6 @@ class TestAutoRouterBenchmarks:
from datetime import datetime, timedelta, timezone
from unittest.mock import AsyncMock, MagicMock
-from fastapi import HTTPException
from litellm.proxy.management_endpoints.auto_router_endpoints import (
get_shadow_eval_job,
diff --git a/tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py b/tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py
index e39b09ae073..a4c2b7c06bf 100644
--- a/tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py
+++ b/tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py
@@ -4529,7 +4529,6 @@ async def test_new_team_org_scoped_budget_bypasses_user_limit():
from fastapi import Request
from litellm.proxy._types import (
- LiteLLM_OrganizationTable,
LiteLLM_UserTable,
NewTeamRequest,
UserAPIKeyAuth,
@@ -4674,7 +4673,6 @@ async def test_new_team_org_scoped_models_bypasses_user_limit():
from fastapi import Request
from litellm.proxy._types import (
- LiteLLM_OrganizationTable,
LiteLLM_UserTable,
NewTeamRequest,
UserAPIKeyAuth,
@@ -4964,7 +4962,6 @@ async def test_new_team_org_scoped_budget_exceeds_org_limit():
from litellm.proxy._types import (
LiteLLM_BudgetTable,
- LiteLLM_OrganizationTable,
NewTeamRequest,
ProxyException,
UserAPIKeyAuth,
@@ -5044,7 +5041,6 @@ async def test_new_team_org_scoped_models_not_in_org_models():
from litellm.proxy._types import (
LiteLLM_BudgetTable,
- LiteLLM_OrganizationTable,
NewTeamRequest,
ProxyException,
UserAPIKeyAuth,
@@ -5633,7 +5629,6 @@ async def test_update_team_org_scoped_budget_exceeds_org_limit():
from litellm.proxy._types import (
LiteLLM_BudgetTable,
- LiteLLM_OrganizationTable,
ProxyException,
UpdateTeamRequest,
UserAPIKeyAuth,
@@ -5813,7 +5808,6 @@ async def test_update_team_org_scoped_budget_bypasses_user_limit(
from litellm.proxy._types import (
LiteLLM_BudgetTable,
- LiteLLM_OrganizationTable,
LiteLLM_UserTable,
UpdateTeamRequest,
UserAPIKeyAuth,
@@ -5929,7 +5923,6 @@ async def test_update_team_org_scoped_models_bypasses_user_limit(
from fastapi import Request
from litellm.proxy._types import (
- LiteLLM_OrganizationTable,
UpdateTeamRequest,
UserAPIKeyAuth,
)
@@ -6031,7 +6024,6 @@ async def test_update_team_org_scoped_models_not_in_org_models():
from fastapi import Request
from litellm.proxy._types import (
- LiteLLM_OrganizationTable,
ProxyException,
UpdateTeamRequest,
UserAPIKeyAuth,
@@ -6120,7 +6112,6 @@ async def test_update_team_org_scoped_models_with_all_proxy_models(
from fastapi import Request
from litellm.proxy._types import (
- LiteLLM_OrganizationTable,
SpecialModelNames,
UpdateTeamRequest,
UserAPIKeyAuth,
@@ -6403,7 +6394,6 @@ async def test_new_team_org_scoped_tpm_exceeds_org_limit():
from litellm.proxy._types import (
LiteLLM_BudgetTable,
- LiteLLM_OrganizationTable,
NewTeamRequest,
ProxyException,
UserAPIKeyAuth,
@@ -6479,7 +6469,6 @@ async def test_new_team_org_scoped_rpm_exceeds_org_limit():
from litellm.proxy._types import (
LiteLLM_BudgetTable,
- LiteLLM_OrganizationTable,
NewTeamRequest,
ProxyException,
UserAPIKeyAuth,
@@ -6556,7 +6545,6 @@ async def test_new_team_org_scoped_tpm_rpm_bypasses_user_limit():
from litellm.proxy._types import (
LiteLLM_BudgetTable,
- LiteLLM_OrganizationTable,
LiteLLM_TeamTable,
NewTeamRequest,
UserAPIKeyAuth,
@@ -6665,7 +6653,6 @@ async def test_update_team_org_scoped_tpm_exceeds_org_limit():
from litellm.proxy._types import (
LiteLLM_BudgetTable,
- LiteLLM_OrganizationTable,
ProxyException,
UpdateTeamRequest,
UserAPIKeyAuth,
@@ -6752,7 +6739,6 @@ async def test_update_team_org_scoped_rpm_exceeds_org_limit():
from litellm.proxy._types import (
LiteLLM_BudgetTable,
- LiteLLM_OrganizationTable,
ProxyException,
UpdateTeamRequest,
UserAPIKeyAuth,
@@ -6842,7 +6828,6 @@ async def test_update_team_org_scoped_tpm_rpm_bypasses_user_limit(
from litellm.proxy._types import (
LiteLLM_BudgetTable,
- LiteLLM_OrganizationTable,
LiteLLM_TeamTable,
UpdateTeamRequest,
UserAPIKeyAuth,
@@ -6948,7 +6933,6 @@ async def test_update_team_guardrails_with_org_id(
from fastapi import Request
from litellm.proxy._types import (
- LiteLLM_OrganizationTable,
LiteLLM_TeamTable,
UpdateTeamRequest,
UserAPIKeyAuth,
diff --git a/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py b/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py
index d3237f5f49d..6568f6aeacf 100644
--- a/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py
+++ b/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py
@@ -2405,9 +2405,6 @@ class TestMilvusProxyRoute:
"""
Test successful Milvus proxy route with valid managed vector store index
"""
- from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
- milvus_proxy_route,
- )
collection_name = "dall-e-6"
vector_store_name = "milvus-store-1"
@@ -2518,9 +2515,6 @@ class TestMilvusProxyRoute:
"""
from fastapi import HTTPException
- from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
- milvus_proxy_route,
- )
mock_request = MagicMock(spec=Request)
mock_response = MagicMock(spec=Response)
@@ -2555,9 +2549,6 @@ class TestMilvusProxyRoute:
"""
from fastapi import HTTPException
- from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
- milvus_proxy_route,
- )
mock_request = MagicMock(spec=Request)
mock_response = MagicMock(spec=Response)
@@ -2587,9 +2578,6 @@ class TestMilvusProxyRoute:
"""
from fastapi import HTTPException
- from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
- milvus_proxy_route,
- )
collection_name = "test-collection"
@@ -2629,9 +2617,6 @@ class TestMilvusProxyRoute:
"""
from fastapi import HTTPException
- from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
- milvus_proxy_route,
- )
collection_name = "unmanaged-collection"
@@ -2672,9 +2657,6 @@ class TestMilvusProxyRoute:
"""
Test that missing vector store raises Exception
"""
- from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
- milvus_proxy_route,
- )
collection_name = "test-collection"
vector_store_name = "missing-store"
@@ -2731,9 +2713,6 @@ class TestMilvusProxyRoute:
"""
Test that missing api_base raises Exception
"""
- from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
- milvus_proxy_route,
- )
collection_name = "test-collection"
vector_store_name = "milvus-store-1"
@@ -2797,9 +2776,6 @@ class TestMilvusProxyRoute:
"""
Test that endpoint without leading slash is handled correctly
"""
- from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
- milvus_proxy_route,
- )
collection_name = "test-collection"
vector_store_name = "milvus-store-1"
@@ -2877,9 +2853,6 @@ class TestOpenAIPassthroughRoute:
This verifies the fix for issue #18865 where /openai/v1/responses was being
routed to LiteLLM's native implementation instead of passthrough
"""
- from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
- openai_proxy_route,
- )
# Mock request for Responses API
mock_request = MagicMock(spec=Request)
@@ -2931,9 +2904,6 @@ class TestOpenAIPassthroughRoute:
"""
Test that /openai_passthrough works for chat completions
"""
- from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
- openai_proxy_route,
- )
mock_request = MagicMock(spec=Request)
mock_request.method = "POST"
@@ -2976,9 +2946,6 @@ class TestOpenAIPassthroughRoute:
"""
Test that missing OPENAI_API_KEY raises an exception
"""
- from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
- openai_proxy_route,
- )
mock_request = MagicMock(spec=Request)
mock_response = MagicMock(spec=Response)
@@ -3003,9 +2970,6 @@ class TestOpenAIPassthroughRoute:
"""
Test that /openai_passthrough works for Assistants API endpoints
"""
- from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
- openai_proxy_route,
- )
mock_request = MagicMock(spec=Request)
mock_request.method = "POST"
diff --git a/tests/test_litellm/proxy/prompts/test_prompt_endpoints.py b/tests/test_litellm/proxy/prompts/test_prompt_endpoints.py
index 57ad6acae3b..6ebb10eff76 100644
--- a/tests/test_litellm/proxy/prompts/test_prompt_endpoints.py
+++ b/tests/test_litellm/proxy/prompts/test_prompt_endpoints.py
@@ -206,7 +206,7 @@ class TestPromptVersionsEndpoint:
"""
Test that get_prompt_versions returns all versions of a prompt sorted by version number
"""
- from unittest.mock import MagicMock, patch
+ from unittest.mock import patch
from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth
from litellm.proxy.prompts.prompt_endpoints import get_prompt_versions
diff --git a/tests/test_litellm/proxy/test_common_request_processing.py b/tests/test_litellm/proxy/test_common_request_processing.py
index 716fba370df..8074f475af2 100644
--- a/tests/test_litellm/proxy/test_common_request_processing.py
+++ b/tests/test_litellm/proxy/test_common_request_processing.py
@@ -28,7 +28,6 @@ from litellm.proxy.common_request_processing import (
_get_cost_breakdown_from_logging_obj,
_has_attribute_error_in_chain,
_is_azure_model_router_request,
- _UpstreamClosingStreamingResponse,
open_sse_before_first_byte,
ttft_keepalive_interval,
_override_openai_response_model,
diff --git a/tests/test_litellm/proxy/test_litellm_pre_call_utils.py b/tests/test_litellm/proxy/test_litellm_pre_call_utils.py
index 636974d5deb..d14c89342e9 100644
--- a/tests/test_litellm/proxy/test_litellm_pre_call_utils.py
+++ b/tests/test_litellm/proxy/test_litellm_pre_call_utils.py
@@ -2736,10 +2736,8 @@ def test_add_headers_to_llm_call_by_model_group_existing_headers_in_data():
litellm.model_group_settings = original_model_group_settings
-import json
import time
from typing import Optional
-from unittest.mock import AsyncMock
from fastapi.responses import Response
diff --git a/tests/test_litellm/proxy/test_proxy_server.py b/tests/test_litellm/proxy/test_proxy_server.py
index 83e9095c8ec..343b274cd8c 100644
--- a/tests/test_litellm/proxy/test_proxy_server.py
+++ b/tests/test_litellm/proxy/test_proxy_server.py
@@ -3344,7 +3344,7 @@ async def test_write_config_to_file(monkeypatch):
"""
Do not write config to file if store_model_in_db is True
"""
- from unittest.mock import AsyncMock, MagicMock, mock_open, patch
+ from unittest.mock import AsyncMock, MagicMock, patch
from litellm.proxy.proxy_server import ProxyConfig
@@ -3392,7 +3392,7 @@ async def test_write_config_to_file_when_store_model_in_db_false(monkeypatch):
"""
Test that config IS written to file when store_model_in_db is False
"""
- from unittest.mock import AsyncMock, MagicMock, mock_open, patch
+ from unittest.mock import AsyncMock, MagicMock, patch
from litellm.proxy.proxy_server import ProxyConfig
diff --git a/tests/test_litellm/responses/litellm_completion_transformation/test_session_handler_with_cold_storage.py b/tests/test_litellm/responses/litellm_completion_transformation/test_session_handler_with_cold_storage.py
index e579890255c..f2fbcda59a4 100644
--- a/tests/test_litellm/responses/litellm_completion_transformation/test_session_handler_with_cold_storage.py
+++ b/tests/test_litellm/responses/litellm_completion_transformation/test_session_handler_with_cold_storage.py
@@ -36,7 +36,6 @@ class TestColdStorageObjectKeyIntegration:
This test verifies that the StandardLoggingMetadata TypedDict has the
cold_storage_object_key field for storing S3/GCS object keys.
"""
- from litellm.types.utils import StandardLoggingMetadata
# Create a StandardLoggingMetadata instance with cold_storage_object_key
metadata = StandardLoggingMetadata(
diff --git a/tests/test_litellm/router_strategy/test_base_routing_strategy.py b/tests/test_litellm/router_strategy/test_base_routing_strategy.py
index 02a6ce4be2a..70259605b2f 100644
--- a/tests/test_litellm/router_strategy/test_base_routing_strategy.py
+++ b/tests/test_litellm/router_strategy/test_base_routing_strategy.py
@@ -12,7 +12,6 @@ sys.path.insert(
import asyncio
from unittest.mock import MagicMock, patch
-import pytest
from litellm.caching.caching import DualCache
from litellm.caching.redis_cache import RedisPipelineIncrementOperation
diff --git a/tests/test_litellm/test_utils.py b/tests/test_litellm/test_utils.py
index 075b455e4b5..a9ddade98ea 100644
--- a/tests/test_litellm/test_utils.py
+++ b/tests/test_litellm/test_utils.py
@@ -1374,7 +1374,7 @@ def test_get_provider_rerank_config():
Test the get_provider_rerank_config function for various providers
"""
from litellm import HostedVLLMRerankConfig
- from litellm.utils import LlmProviders, ProviderConfigManager
+ from litellm.utils import LlmProviders
# Test for hosted_vllm provider
config = ProviderConfigManager.get_provider_rerank_config(
@@ -1497,7 +1497,7 @@ def test_get_model_info_shows_supports_computer_use():
def test_pre_process_non_default_params(model, custom_llm_provider):
from pydantic import BaseModel
- from litellm.utils import ProviderConfigManager, pre_process_non_default_params
+ from litellm.utils import pre_process_non_default_params
provider_config = ProviderConfigManager.get_provider_chat_config(
model=model, provider=LlmProviders(custom_llm_provider)
@@ -2364,7 +2364,6 @@ def test_anthropic_claude_4_invoke_chat_provider_config():
from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude3_transformation import (
AmazonAnthropicClaudeConfig,
)
- from litellm.utils import ProviderConfigManager
config = ProviderConfigManager.get_provider_chat_config(
model="invoke/us.anthropic.claude-sonnet-4-20250514-v1:0",
@@ -3251,7 +3250,6 @@ class TestProxyLoggingBudgetAlerts:
def test_azure_ai_claude_provider_config():
"""Test that Azure AI Claude models return AzureAnthropicConfig for proper tool transformation."""
from litellm import AzureAIStudioConfig, AzureAnthropicConfig
- from litellm.utils import ProviderConfigManager
# Claude models should return AzureAnthropicConfig
config = ProviderConfigManager.get_provider_chat_config(
@@ -4319,7 +4317,6 @@ class TestGetOptionalParamsTencent:
from litellm.llms.tencent.messages.transformation import (
TencentAnthropicMessagesConfig,
)
- from litellm.utils import ProviderConfigManager
config = ProviderConfigManager.get_provider_anthropic_messages_config(
model="deepseek-v4-pro",
diff --git a/tests/test_litellm/vector_stores/test_vector_store_registry.py b/tests/test_litellm/vector_stores/test_vector_store_registry.py
index 9f4c5a905b3..85ff8a1bcae 100644
--- a/tests/test_litellm/vector_stores/test_vector_store_registry.py
+++ b/tests/test_litellm/vector_stores/test_vector_store_registry.py
@@ -13,7 +13,7 @@ sys.path.insert(
) # Adds the parent directory to the system path
from datetime import datetime, timezone
-from unittest.mock import MagicMock, patch
+from unittest.mock import MagicMock
import litellm
from litellm.types.vector_stores import LiteLLM_ManagedVectorStore
diff --git a/tests/test_team_logging.py b/tests/test_team_logging.py
index 9e89d945eda..86b357d9d4a 100644
--- a/tests/test_team_logging.py
+++ b/tests/test_team_logging.py
@@ -7,7 +7,6 @@ import aiohttp
import os
import dotenv
from dotenv import load_dotenv
-import pytest
load_dotenv()
diff --git a/tests/test_users.py b/tests/test_users.py
index 57fbb0483e4..a6d3d0a7dc3 100644
--- a/tests/test_users.py
+++ b/tests/test_users.py
@@ -7,7 +7,6 @@ import time
from openai import AsyncOpenAI
from tests.test_team import list_teams
from typing import Optional
-from tests.test_keys import generate_key
from fastapi import HTTPException
@@ -320,7 +319,6 @@ async def test_user_model_access():
import json
from litellm._uuid import uuid
import pytest
-import aiohttp
from typing import Dict, Tuple
diff --git a/tests/unified_google_tests/conftest.py b/tests/unified_google_tests/conftest.py
index c6b3fb82d0e..d2c6830c273 100644
--- a/tests/unified_google_tests/conftest.py
+++ b/tests/unified_google_tests/conftest.py
@@ -150,7 +150,6 @@ def setup_and_teardown(request):
0, os.path.abspath("../..")
) # Adds the project directory to the system path
- import litellm
if "google_genai_proxy_url" not in request.fixturenames:
importlib.reload(litellm)
diff --git a/tests/vector_store_tests/base_vector_store_test.py b/tests/vector_store_tests/base_vector_store_test.py
index 4ca643f085a..4093ea7b43b 100644
--- a/tests/vector_store_tests/base_vector_store_test.py
+++ b/tests/vector_store_tests/base_vector_store_test.py
@@ -15,7 +15,6 @@ sys.path.insert(
import litellm
from abc import ABC, abstractmethod
from litellm.integrations.custom_logger import CustomLogger
-import json
from litellm.types.utils import StandardLoggingPayload
diff --git a/tests/vector_store_tests/conftest.py b/tests/vector_store_tests/conftest.py
index b3561d8a626..41da685895b 100644
--- a/tests/vector_store_tests/conftest.py
+++ b/tests/vector_store_tests/conftest.py
@@ -22,7 +22,6 @@ def setup_and_teardown():
0, os.path.abspath("../..")
) # Adds the project directory to the system path
- import litellm
from litellm import Router
importlib.reload(litellm)