Merge pull request #37878 from BerriAI/litellm_ruff_no_duplicate_definitions

test: enforce F811 so a duplicate definition cannot silently replace the first
This commit is contained in:
ryan-crabbe-berri 2026-08-21 12:49:43 -07:00 committed by GitHub
commit ed02a121dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
172 changed files with 73 additions and 367 deletions

View file

@ -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"]

View file

@ -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"

View file

@ -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()

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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__), "../../..")))

View file

@ -4,7 +4,6 @@ import pytest
from dotenv import load_dotenv
load_dotenv()
import os
import httpx
sys.path.insert(

View file

@ -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

View file

@ -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(

View file

@ -8,7 +8,6 @@ import pytest
from dotenv import load_dotenv
load_dotenv()
import os
from litellm.proxy._types import LiteLLM_BudgetTableFull

View file

@ -9,7 +9,6 @@ from dotenv import load_dotenv
import json
load_dotenv()
import os
import tempfile
from uuid import uuid4

View file

@ -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,

View file

@ -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)

View file

@ -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

View file

@ -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 = {

View file

@ -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,

View file

@ -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": [

View file

@ -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("../..")

View file

@ -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",

View file

@ -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()

View file

@ -13,7 +13,6 @@ import litellm.types
load_dotenv()
import io
import os
import json
sys.path.insert(

View file

@ -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():

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -11,7 +11,6 @@ from litellm.llms.anthropic.chat import ModelResponseIterator
load_dotenv()
import io
import os
sys.path.insert(
0, os.path.abspath("../..")

View file

@ -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():

View file

@ -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(

View file

@ -8,7 +8,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
import os
from typing import Optional, Dict
sys.path.insert(

View file

@ -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("../..")

View file

@ -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

View file

@ -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

View file

@ -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,
)

View file

@ -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"

View file

@ -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

View file

@ -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("../..")

View file

@ -12,7 +12,6 @@ sys.path.insert(
import concurrent
from dotenv import load_dotenv
import asyncio
import litellm

View file

@ -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=[

View file

@ -6,7 +6,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
import os
from test_streaming import streaming_format_tests

View file

@ -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()

View file

@ -6,7 +6,6 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
import os
sys.path.insert(
0, os.path.abspath("../..")

View file

@ -7,7 +7,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
import os
sys.path.insert(
0, os.path.abspath("../..")

View file

@ -215,9 +215,7 @@ def test_locked_aiohttp_version_is_not_pool_poisoning():
import os
import subprocess
import time
import pytest
import requests

View file

@ -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,

View file

@ -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

View file

@ -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

View file

@ -7,7 +7,6 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
import os
sys.path.insert(
0, os.path.abspath("../..")

View file

@ -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

View file

@ -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

View file

@ -10,7 +10,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
import os
sys.path.insert(
0, os.path.abspath("../..")

View file

@ -6,7 +6,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
import os
sys.path.insert(
0, os.path.abspath("../..")

View file

@ -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("../..")

View file

@ -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("../..")

View file

@ -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):

View file

@ -8,7 +8,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
import os
sys.path.insert(
0, os.path.abspath("../..")

View file

@ -6,7 +6,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
import os
sys.path.insert(
0, os.path.abspath("../..")

View file

@ -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("../..")

View file

@ -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("../..")

View file

@ -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()

View file

@ -11,7 +11,6 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
import os
sys.path.insert(
0, os.path.abspath("../..")

View file

@ -9,7 +9,6 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
import os
sys.path.insert(
0, os.path.abspath("../..")

View file

@ -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("../..")

View file

@ -13,7 +13,6 @@ from dotenv import load_dotenv
load_dotenv()
import copy
import os
sys.path.insert(
0, os.path.abspath("../..")

View file

@ -8,7 +8,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
import os
sys.path.insert(
0, os.path.abspath("../..")

View file

@ -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=[
{

View file

@ -7,7 +7,6 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
import os
sys.path.insert(
0, os.path.abspath("../..")

View file

@ -6,7 +6,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
import os
sys.path.insert(
0, os.path.abspath("../..")

View file

@ -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("../..")

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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,
)

View file

@ -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 = [
{

View file

@ -8,7 +8,6 @@ from dotenv import load_dotenv
load_dotenv()
import io
import os
sys.path.insert(
0, os.path.abspath("../..")

View file

@ -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 = [
{

View file

@ -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,

View file

@ -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(

View file

@ -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",

View file

@ -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 *

View file

@ -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 *

View file

@ -9,7 +9,6 @@ from fastapi.routing import APIRoute
load_dotenv()
import io
import os
import time
import json

View file

@ -9,8 +9,6 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
import os
import asyncio
sys.path.insert(
0, os.path.abspath("../..")

View file

@ -9,7 +9,6 @@ from fastapi.routing import APIRoute
load_dotenv()
import io
import os
import time
# this file is to test litellm/proxy

View file

@ -9,7 +9,6 @@ from fastapi.routing import APIRoute
load_dotenv()
import io
import os
import time
import json

View file

@ -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()

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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)

View file

@ -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,

View file

@ -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,
)

View file

@ -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()

View file

@ -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)

View file

@ -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(

Some files were not shown because too many files have changed in this diff Show more