Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ruff-tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@
# 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
# still has to run on 3.10.

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"]
11 changes: 5 additions & 6 deletions tests/audio_tests/test_audio_speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from dotenv import load_dotenv

load_dotenv()
import os

sys.path.insert(
0, os.path.abspath("../..")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions tests/audio_tests/test_whisper.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def _audio_file2():
sys.path.insert(
0, os.path.abspath("../")
) # Adds the parent directory to the system path
import litellm
from litellm import Router


Expand Down Expand Up @@ -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()

Expand Down
1 change: 0 additions & 1 deletion tests/enterprise/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,6 @@ def observe(self, value):
@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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
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

Expand Down
2 changes: 0 additions & 2 deletions tests/guardrails_tests/test_custom_guardrail.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@

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
Expand Down
1 change: 0 additions & 1 deletion tests/litellm_utils_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 0 additions & 2 deletions tests/litellm_utils_tests/test_aws_secret_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
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__), "../../..")))
Expand Down
1 change: 0 additions & 1 deletion tests/litellm_utils_tests/test_hashicorp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from dotenv import load_dotenv

load_dotenv()
import os
import httpx

sys.path.insert(
Expand Down
10 changes: 5 additions & 5 deletions tests/litellm_utils_tests/test_health_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,19 +785,19 @@ async def mock_health_check(litellm_params, mode=None, prompt=None, input=None):

# 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
Expand Down
2 changes: 1 addition & 1 deletion tests/litellm_utils_tests/test_logging_callback_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion tests/litellm_utils_tests/test_proxy_budget_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from dotenv import load_dotenv

load_dotenv()
import os

from litellm.proxy._types import LiteLLM_BudgetTableFull

Expand Down
1 change: 0 additions & 1 deletion tests/litellm_utils_tests/test_secret_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import json

load_dotenv()
import os
import tempfile
from uuid import uuid4

Expand Down
1 change: 0 additions & 1 deletion tests/llm_responses_api_testing/base_responses_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
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,
Expand Down
1 change: 0 additions & 1 deletion tests/llm_responses_api_testing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
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
Expand Down
3 changes: 1 addition & 2 deletions tests/llm_responses_api_testing/test_azure_responses_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
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,
Expand Down
7 changes: 0 additions & 7 deletions tests/llm_translation/test_anthropic_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

load_dotenv()
import io
import os

sys.path.insert(
0, os.path.abspath("../..")
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -951,7 +949,6 @@ def test_anthropic_citations_api():
"""
Test the citations API
"""
from litellm import completion

try:
resp = completion(
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -1044,7 +1040,6 @@ def test_anthropic_citations_api_streaming():
],
)
def test_anthropic_thinking_output(model):
from litellm import completion

litellm._turn_on_debug()

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -1528,7 +1522,6 @@ def test_anthropic_tool_cache_control():


def test_anthropic_streaming():
from litellm import completion

request_data = {
"messages": [
Expand Down
1 change: 0 additions & 1 deletion tests/llm_translation/test_azure_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

load_dotenv()
import io
import os

sys.path.insert(
0, os.path.abspath("../..")
Expand Down
2 changes: 0 additions & 2 deletions tests/llm_translation/test_azure_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions tests/llm_translation/test_bedrock_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

load_dotenv()
import io
import os
import json

sys.path.insert(
Expand Down Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion tests/llm_translation/test_bedrock_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

load_dotenv()
import io
import os
import json

sys.path.insert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@
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():
Expand Down
1 change: 0 additions & 1 deletion tests/llm_translation/test_bedrock_govcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,6 @@ def test_govcloud_completion_cost_calculation(self, mock_completion):
@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

Expand Down
Loading
Loading