diff --git a/test-quality-budget.json b/test-quality-budget.json index 3c12371f02f..4802dbefd13 100644 --- a/test-quality-budget.json +++ b/test-quality-budget.json @@ -6,7 +6,7 @@ "limit": 737 }, "TQ003": { - "limit": 62 + "limit": 20 }, "TQ004": { "limit": 469 diff --git a/tests/test_litellm/litellm_core_utils/test_request_timeout_resolver.py b/tests/test_litellm/litellm_core_utils/test_request_timeout_resolver.py index 4e016622f1c..e5c379f264a 100644 --- a/tests/test_litellm/litellm_core_utils/test_request_timeout_resolver.py +++ b/tests/test_litellm/litellm_core_utils/test_request_timeout_resolver.py @@ -6,13 +6,8 @@ at the package default. This is what lets request_timeout act as an independent per-attempt timeout instead of being indistinguishable from "nobody set it". """ -import os -import sys - import pytest -sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../.."))) - import litellm from litellm.constants import DEFAULT_REQUEST_TIMEOUT_SECONDS from litellm.litellm_core_utils.request_timeout_resolver import ( diff --git a/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_handler_output_config_passthrough.py b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_handler_output_config_passthrough.py index a944afc6152..02d0549a0aa 100644 --- a/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_handler_output_config_passthrough.py +++ b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_handler_output_config_passthrough.py @@ -25,18 +25,11 @@ Tests cover (consolidating PRs #23706 and #22727): the fallback inference path from being exercised). """ -import os -import sys -from unittest.mock import MagicMock, patch -import pytest # Anchor sys.path to this file's location — not the working-directory-relative # pattern Greptile flagged on PR #23706. Resolves correctly regardless of # where pytest is invoked from. -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../../..")) -) from litellm.llms.anthropic.experimental_pass_through.adapters.handler import ( ANTHROPIC_ONLY_REQUEST_KEYS, diff --git a/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_handler_prompt_cache_key.py b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_handler_prompt_cache_key.py index 7dc7507120f..4933effb490 100644 --- a/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_handler_prompt_cache_key.py +++ b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_handler_prompt_cache_key.py @@ -1,11 +1,7 @@ import json -import os -import sys import pytest -sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../../.."))) - from litellm.llms.anthropic.experimental_pass_through.adapters.handler import ( LiteLLMMessagesToCompletionTransformationHandler, ) diff --git a/tests/test_litellm/llms/anthropic/experimental_pass_through/responses_adapters/test_responses_adapters_handler.py b/tests/test_litellm/llms/anthropic/experimental_pass_through/responses_adapters/test_responses_adapters_handler.py index b66075f691b..782e0873a55 100644 --- a/tests/test_litellm/llms/anthropic/experimental_pass_through/responses_adapters/test_responses_adapters_handler.py +++ b/tests/test_litellm/llms/anthropic/experimental_pass_through/responses_adapters/test_responses_adapters_handler.py @@ -1,14 +1,10 @@ import datetime import json -import os -import sys from unittest.mock import AsyncMock, patch import pytest import respx -sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../../.."))) - import litellm from litellm.llms.anthropic.experimental_pass_through.responses_adapters.handler import ( LiteLLMMessagesToResponsesAPIHandler, diff --git a/tests/test_litellm/llms/anthropic/experimental_pass_through/responses_adapters/test_responses_adapters_streaming_iterator.py b/tests/test_litellm/llms/anthropic/experimental_pass_through/responses_adapters/test_responses_adapters_streaming_iterator.py index bfe2d6b7cea..f1efb477090 100644 --- a/tests/test_litellm/llms/anthropic/experimental_pass_through/responses_adapters/test_responses_adapters_streaming_iterator.py +++ b/tests/test_litellm/llms/anthropic/experimental_pass_through/responses_adapters/test_responses_adapters_streaming_iterator.py @@ -4,12 +4,8 @@ Tests for AnthropicResponsesStreamWrapper """ import asyncio -import os -import sys from types import SimpleNamespace -sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../../.."))) - from litellm.litellm_core_utils.prompt_templates.common_utils import ( encrypted_reasoning_signature, ) diff --git a/tests/test_litellm/llms/anthropic/test_anthropic_common_utils.py b/tests/test_litellm/llms/anthropic/test_anthropic_common_utils.py index e1b39c4ba13..46cc708c483 100644 --- a/tests/test_litellm/llms/anthropic/test_anthropic_common_utils.py +++ b/tests/test_litellm/llms/anthropic/test_anthropic_common_utils.py @@ -11,15 +11,11 @@ Verifies that: """ import json -import os -import sys from types import SimpleNamespace from unittest.mock import patch import pytest -sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../.."))) - # Fake tokens for testing (not real secrets) FAKE_OAUTH_TOKEN = "sk-ant-oat01-fake-token-for-testing-123456789abcdef" FAKE_REGULAR_KEY = "sk-ant-api03-regular-key-for-testing-123456789" diff --git a/tests/test_litellm/llms/anthropic/test_count_tokens_oauth.py b/tests/test_litellm/llms/anthropic/test_count_tokens_oauth.py index bcfc56577eb..3180bae7f6a 100644 --- a/tests/test_litellm/llms/anthropic/test_count_tokens_oauth.py +++ b/tests/test_litellm/llms/anthropic/test_count_tokens_oauth.py @@ -7,12 +7,6 @@ Verifies that get_required_headers() correctly handles OAuth tokens Regression test for https://github.com/BerriAI/litellm/issues/22040 """ -import os -import sys - -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../..")) -) from litellm.llms.anthropic.count_tokens.transformation import ( AnthropicCountTokensConfig, diff --git a/tests/test_litellm/llms/anthropic/test_message_sanitization.py b/tests/test_litellm/llms/anthropic/test_message_sanitization.py index 79ed321d0ee..73fadcd709b 100644 --- a/tests/test_litellm/llms/anthropic/test_message_sanitization.py +++ b/tests/test_litellm/llms/anthropic/test_message_sanitization.py @@ -8,13 +8,6 @@ C. Empty text content """ import pytest -import sys -import os - -# Add the parent directory to the path so we can import litellm -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../..")) -) import litellm from litellm.litellm_core_utils.prompt_templates.factory import ( diff --git a/tests/test_litellm/llms/azure/chat/test_azure_chat_gpt_transformation.py b/tests/test_litellm/llms/azure/chat/test_azure_chat_gpt_transformation.py index bc6cb0c0fed..d9fb6a3da88 100644 --- a/tests/test_litellm/llms/azure/chat/test_azure_chat_gpt_transformation.py +++ b/tests/test_litellm/llms/azure/chat/test_azure_chat_gpt_transformation.py @@ -1,14 +1,8 @@ -import os -import sys from typing import Final import pytest from pydantic import TypeAdapter -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../..")) -) - import litellm from litellm.litellm_core_utils.prompt_templates.common_utils import TOOL_RESULT_IMAGE_BOUNDARY from litellm.llms.azure.chat.gpt_5_transformation import AzureOpenAIGPT5Config diff --git a/tests/test_litellm/llms/azure/test_azure_embedding.py b/tests/test_litellm/llms/azure/test_azure_embedding.py index 22ee503ef0d..233c6f6612a 100644 --- a/tests/test_litellm/llms/azure/test_azure_embedding.py +++ b/tests/test_litellm/llms/azure/test_azure_embedding.py @@ -1,13 +1,7 @@ -import os -import sys from unittest.mock import MagicMock, patch import pytest -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../..")) -) - from litellm.llms.azure.azure import AzureChatCompletion from litellm.types.utils import EmbeddingResponse, Usage diff --git a/tests/test_litellm/llms/azure/videos/test_azure_video_transformation.py b/tests/test_litellm/llms/azure/videos/test_azure_video_transformation.py index 97c9e590d08..f0074a1729e 100644 --- a/tests/test_litellm/llms/azure/videos/test_azure_video_transformation.py +++ b/tests/test_litellm/llms/azure/videos/test_azure_video_transformation.py @@ -1,21 +1,9 @@ -import json -import os -import sys -from typing import Any, Dict, Optional -from unittest.mock import MagicMock, patch, Mock, mock_open +from unittest.mock import MagicMock, patch, mock_open import pytest -import httpx -# Add the parent directory to the system path -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../../..")) -) - -import litellm from litellm.llms.azure.videos.transformation import AzureVideoConfig from litellm.types.videos.main import ( VideoObject, - VideoResponse, VideoCreateOptionalRequestParams, ) from litellm.types.router import GenericLiteLLMParams diff --git a/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_handler.py b/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_handler.py index dcb6aec8091..062ceae5349 100644 --- a/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_handler.py +++ b/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_handler.py @@ -1,15 +1,7 @@ -import os -import sys - -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../..")) -) import json from unittest.mock import MagicMock, patch -import pytest - from litellm.llms.azure_ai.anthropic.handler import AzureAnthropicChatCompletion from litellm.types.utils import ModelResponse diff --git a/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_messages_transformation.py b/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_messages_transformation.py index 326edde743d..094c252223d 100644 --- a/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_messages_transformation.py +++ b/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_messages_transformation.py @@ -1,12 +1,6 @@ import copy import json import os -import sys - -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../..")) -) - from unittest.mock import patch import pytest diff --git a/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_provider_routing.py b/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_provider_routing.py index db1daa013c2..d1aba9c5db5 100644 --- a/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_provider_routing.py +++ b/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_provider_routing.py @@ -1,11 +1,4 @@ -import os -import sys -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../..")) -) - -import pytest from litellm.litellm_core_utils.get_llm_provider_logic import ( _is_azure_claude_model, diff --git a/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_transformation.py b/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_transformation.py index 9e2bfb08852..0f9611f34b0 100644 --- a/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_transformation.py +++ b/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_transformation.py @@ -1,11 +1,5 @@ -import os -import sys -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../..")) -) - -from unittest.mock import MagicMock, patch +from unittest.mock import patch import pytest diff --git a/tests/test_litellm/llms/azure_ai/claude/test_main_azure_anthropic_timeout.py b/tests/test_litellm/llms/azure_ai/claude/test_main_azure_anthropic_timeout.py index e08098e9aab..e56be88cc2d 100644 --- a/tests/test_litellm/llms/azure_ai/claude/test_main_azure_anthropic_timeout.py +++ b/tests/test_litellm/llms/azure_ai/claude/test_main_azure_anthropic_timeout.py @@ -2,14 +2,8 @@ Ensure litellm.completion() forwards timeout to Azure Anthropic handler (main.py dispatch). """ -import os -import sys from unittest.mock import MagicMock, patch -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../..")) -) - from litellm import completion from litellm.types.utils import ModelResponse diff --git a/tests/test_litellm/llms/custom_httpx/test_gemini_session_leak.py b/tests/test_litellm/llms/custom_httpx/test_gemini_session_leak.py index 9a4c6164db6..6483fcaa389 100755 --- a/tests/test_litellm/llms/custom_httpx/test_gemini_session_leak.py +++ b/tests/test_litellm/llms/custom_httpx/test_gemini_session_leak.py @@ -11,13 +11,9 @@ Validates that: import asyncio import gc import sys -from pathlib import Path import pytest -# Add litellm to path -sys.path.insert(0, str(Path(__file__).parent)) - async def test_aiohttp_handler_cleanup(): """Test BaseLLMAIOHTTPHandler session cleanup via __del__""" diff --git a/tests/test_litellm/llms/databricks/test_databricks_e2e.py b/tests/test_litellm/llms/databricks/test_databricks_e2e.py index 669f9e94639..c7d42dbdf2a 100644 --- a/tests/test_litellm/llms/databricks/test_databricks_e2e.py +++ b/tests/test_litellm/llms/databricks/test_databricks_e2e.py @@ -72,11 +72,6 @@ pytestmark = pytest.mark.skip( "python tests/test_litellm/llms/databricks/test_databricks_e2e.py" ) -# Add the litellm package to path -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../..")) -) - # Config file path - can be overridden with DATABRICKS_TEST_CONFIG env var DEFAULT_CONFIG_PATH = os.path.expanduser("~/.databricks_litellm_config.txt") CONFIG_FILE = os.environ.get("DATABRICKS_TEST_CONFIG", DEFAULT_CONFIG_PATH) diff --git a/tests/test_litellm/llms/lm_studio/test_lm_studio_chat_transformation.py b/tests/test_litellm/llms/lm_studio/test_lm_studio_chat_transformation.py index 9a4af91b736..338f8d1e712 100644 --- a/tests/test_litellm/llms/lm_studio/test_lm_studio_chat_transformation.py +++ b/tests/test_litellm/llms/lm_studio/test_lm_studio_chat_transformation.py @@ -1,13 +1,7 @@ -import os -import sys from unittest.mock import patch from pydantic import BaseModel -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../..")) -) - from litellm.llms.lm_studio.chat.transformation import LMStudioChatConfig from litellm.utils import get_optional_params 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 25f9645faa0..c1f1cced626 100644 --- a/tests/test_litellm/llms/ollama/test_ollama_chat_transformation.py +++ b/tests/test_litellm/llms/ollama/test_ollama_chat_transformation.py @@ -1,15 +1,7 @@ -import inspect -import os -import sys from typing import cast -import pytest from pydantic import BaseModel -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../..")) -) - from litellm.llms.ollama.chat.transformation import ( OllamaChatConfig, OllamaChatCompletionResponseIterator, diff --git a/tests/test_litellm/llms/openai_like/responses/test_openai_like_responses.py b/tests/test_litellm/llms/openai_like/responses/test_openai_like_responses.py index 1402a8fa7b5..d6628606b00 100644 --- a/tests/test_litellm/llms/openai_like/responses/test_openai_like_responses.py +++ b/tests/test_litellm/llms/openai_like/responses/test_openai_like_responses.py @@ -2,16 +2,8 @@ Tests for OpenAI-like Responses API support in the JSON provider system. """ -import os -import sys from unittest.mock import patch -import pytest - -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../..")) -) - class TestSimpleProviderConfigSupportedEndpoints: """Test the supported_endpoints field on SimpleProviderConfig.""" diff --git a/tests/test_litellm/llms/openai_like/test_abliteration_provider.py b/tests/test_litellm/llms/openai_like/test_abliteration_provider.py index 8b8d443fc44..0888e54a880 100644 --- a/tests/test_litellm/llms/openai_like/test_abliteration_provider.py +++ b/tests/test_litellm/llms/openai_like/test_abliteration_provider.py @@ -2,12 +2,6 @@ Unit tests for the Abliteration OpenAI-like provider. """ -import os -import sys - -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../..")) -) from litellm.llms.openai_like.dynamic_config import create_config_class from litellm.llms.openai_like.json_loader import JSONProviderRegistry diff --git a/tests/test_litellm/llms/openai_like/test_assemblyai_provider.py b/tests/test_litellm/llms/openai_like/test_assemblyai_provider.py index 7eee810b271..b3dee2b05d3 100644 --- a/tests/test_litellm/llms/openai_like/test_assemblyai_provider.py +++ b/tests/test_litellm/llms/openai_like/test_assemblyai_provider.py @@ -2,12 +2,6 @@ Unit tests for the AssemblyAI LLM Gateway OpenAI-like provider. """ -import os -import sys - -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../..")) -) from litellm.llms.openai_like.dynamic_config import create_config_class from litellm.llms.openai_like.json_loader import JSONProviderRegistry diff --git a/tests/test_litellm/llms/openai_like/test_charity_engine.py b/tests/test_litellm/llms/openai_like/test_charity_engine.py index e3dc22fe895..f1e8231d92c 100644 --- a/tests/test_litellm/llms/openai_like/test_charity_engine.py +++ b/tests/test_litellm/llms/openai_like/test_charity_engine.py @@ -2,18 +2,12 @@ Tests for Charity Engine provider configuration and integration. """ -import os -import sys try: import pytest except ImportError: pytest = None -# Add workspace to path -workspace_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../..")) -sys.path.insert(0, workspace_path) - import litellm diff --git a/tests/test_litellm/llms/openai_like/test_empiriolabs_provider.py b/tests/test_litellm/llms/openai_like/test_empiriolabs_provider.py index 58f5e47d09e..7a2a9b02589 100644 --- a/tests/test_litellm/llms/openai_like/test_empiriolabs_provider.py +++ b/tests/test_litellm/llms/openai_like/test_empiriolabs_provider.py @@ -2,12 +2,6 @@ Unit tests for the EmpirioLabs OpenAI-like provider. """ -import os -import sys - -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../..")) -) from litellm.llms.openai_like.dynamic_config import create_config_class from litellm.llms.openai_like.json_loader import JSONProviderRegistry diff --git a/tests/test_litellm/llms/openai_like/test_json_providers.py b/tests/test_litellm/llms/openai_like/test_json_providers.py index d84cc8d3237..7cec305e204 100644 --- a/tests/test_litellm/llms/openai_like/test_json_providers.py +++ b/tests/test_litellm/llms/openai_like/test_json_providers.py @@ -3,7 +3,6 @@ Tests for JSON-based provider configuration system. """ import os -import sys from unittest.mock import patch try: @@ -12,9 +11,8 @@ except ImportError: # pytest not available, will run as standalone script pytest = None -# Add workspace to path +# Repo root, used to locate model_prices_and_context_window.json. workspace_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../..")) -sys.path.insert(0, workspace_path) import litellm diff --git a/tests/test_litellm/llms/openai_like/test_xiaomi_mimo.py b/tests/test_litellm/llms/openai_like/test_xiaomi_mimo.py index 8104fb12943..5337372f152 100644 --- a/tests/test_litellm/llms/openai_like/test_xiaomi_mimo.py +++ b/tests/test_litellm/llms/openai_like/test_xiaomi_mimo.py @@ -4,18 +4,12 @@ Related to issue #18794 """ import os -import sys -from unittest.mock import MagicMock, patch try: import pytest except ImportError: pytest = None -# Add workspace to path -workspace_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../..")) -sys.path.insert(0, workspace_path) - import litellm diff --git a/tests/test_litellm/llms/vertex_ai/test_vertex_ai_psc_endpoint_support.py b/tests/test_litellm/llms/vertex_ai/test_vertex_ai_psc_endpoint_support.py index 499bbf6ccd4..66a6ffcef31 100644 --- a/tests/test_litellm/llms/vertex_ai/test_vertex_ai_psc_endpoint_support.py +++ b/tests/test_litellm/llms/vertex_ai/test_vertex_ai_psc_endpoint_support.py @@ -5,13 +5,7 @@ Tests that LiteLLM properly constructs URLs when using custom api_base for PSC endpoints. """ -import os -import sys -import pytest - -# Add the litellm package to the path -sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../../..")) from litellm.llms.vertex_ai.vertex_llm_base import VertexBase diff --git a/tests/test_litellm/proxy/auth/test_banned_params_extra_body.py b/tests/test_litellm/proxy/auth/test_banned_params_extra_body.py index e87b206a40a..4fd91f7aa92 100644 --- a/tests/test_litellm/proxy/auth/test_banned_params_extra_body.py +++ b/tests/test_litellm/proxy/auth/test_banned_params_extra_body.py @@ -5,15 +5,9 @@ descending into it, the banned-param boundary check is bypassed by nesting the same fields under ``extra_body``. """ -import os -import sys import pytest -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../..")) -) - from litellm.proxy.auth.auth_utils import is_request_body_safe # noqa: E402 diff --git a/tests/test_litellm/proxy/proxy_server/conftest.py b/tests/test_litellm/proxy/proxy_server/conftest.py index c545965f9a9..0a37a9356dc 100644 --- a/tests/test_litellm/proxy/proxy_server/conftest.py +++ b/tests/test_litellm/proxy/proxy_server/conftest.py @@ -9,8 +9,6 @@ from __future__ import annotations import contextlib import os -import sys -from pathlib import Path from typing import Any, AsyncIterator, Callable, Dict, Iterator, List, Optional from unittest.mock import AsyncMock, MagicMock @@ -20,7 +18,6 @@ import pytest # matter where pytest is invoked from. With the project installed via # uv this is defensive — `litellm` already resolves through site-packages # — but it lets the harness work in editable-source layouts too. -sys.path.insert(0, str(Path(__file__).resolve().parents[4])) # --------------------------------------------------------------------------- diff --git a/tests/test_litellm/proxy/test_component_allowlists.py b/tests/test_litellm/proxy/test_component_allowlists.py index 0fdb43d60da..7ada757ec20 100644 --- a/tests/test_litellm/proxy/test_component_allowlists.py +++ b/tests/test_litellm/proxy/test_component_allowlists.py @@ -24,7 +24,6 @@ RDS IAM token when ``IAM_TOKEN_DB_AUTH`` is set). """ import os -import sys # Importing ``litellm.proxy.proxy_server`` runs its module-level setup, which # reads ``DATABASE_URL`` (Prisma) and ``LITELLM_MASTER_KEY``. Tier-zero CI @@ -45,10 +44,6 @@ from fastapi.routing import Mount from prometheus_client import make_asgi_app # gateway/ and backend/ live at the repo root, not inside litellm/. -_REPO_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..")) -if _REPO_ROOT not in sys.path: - sys.path.insert(0, _REPO_ROOT) - from backend.routes.allowlist import ( BACKEND_EXACT_PATHS, BACKEND_MOUNT_PATHS, diff --git a/tests/test_litellm/proxy/test_model_level_guardrails.py b/tests/test_litellm/proxy/test_model_level_guardrails.py index a1278e399b5..5d0a924423d 100644 --- a/tests/test_litellm/proxy/test_model_level_guardrails.py +++ b/tests/test_litellm/proxy/test_model_level_guardrails.py @@ -6,17 +6,11 @@ deployment are merged into request metadata and trigger execution for both streaming and non-streaming post_call hooks. """ -import os -import sys - import pytest from unittest.mock import AsyncMock, MagicMock, patch -sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../.."))) - from litellm.proxy.utils import ( _check_and_merge_model_level_guardrails, - _merge_guardrails_with_existing, ) # --------------------------------------------------------------------------- diff --git a/tests/test_litellm/proxy/types_utils/test_db_overlay_remote_module_scrub.py b/tests/test_litellm/proxy/types_utils/test_db_overlay_remote_module_scrub.py index 100ba653f3a..0bbc994b73b 100644 --- a/tests/test_litellm/proxy/types_utils/test_db_overlay_remote_module_scrub.py +++ b/tests/test_litellm/proxy/types_utils/test_db_overlay_remote_module_scrub.py @@ -13,15 +13,9 @@ pass and ``_load_instance_from_remote_storage`` would exec the remote module. """ -import os -import sys import pytest -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../..")) -) - from litellm.proxy.proxy_server import ( # noqa: E402 _scrub_db_overlay_remote_module_loads, ) diff --git a/tests/test_litellm/proxy/types_utils/test_get_instance_fn_runtime_gate.py b/tests/test_litellm/proxy/types_utils/test_get_instance_fn_runtime_gate.py index 3d76ad54a9c..b2c087b051a 100644 --- a/tests/test_litellm/proxy/types_utils/test_get_instance_fn_runtime_gate.py +++ b/tests/test_litellm/proxy/types_utils/test_get_instance_fn_runtime_gate.py @@ -7,16 +7,10 @@ unaffected — the documented ``litellm_settings.callbacks: ["s3://bucket/module.instance"]`` operator flow continues to work. """ -import os -import sys from unittest.mock import patch import pytest -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../..")) -) - from litellm.proxy.types_utils.utils import get_instance_fn # noqa: E402 diff --git a/tests/test_litellm/proxy/utils/prisma_and_spend/conftest.py b/tests/test_litellm/proxy/utils/prisma_and_spend/conftest.py index fce51c9296c..c0cb82cb3e5 100644 --- a/tests/test_litellm/proxy/utils/prisma_and_spend/conftest.py +++ b/tests/test_litellm/proxy/utils/prisma_and_spend/conftest.py @@ -13,19 +13,14 @@ needing a generated Prisma client or a real database. from __future__ import annotations import asyncio -import sys import threading from dataclasses import dataclass, field from email.message import EmailMessage -from pathlib import Path from typing import Any, Callable, Dict, Iterator, List, Optional from unittest.mock import AsyncMock, MagicMock import pytest -sys.path.insert(0, str(Path(__file__).resolve().parents[5])) - - VOLATILE_KEYS = frozenset( { "created_at", @@ -188,6 +183,7 @@ def patched_prisma_import(monkeypatch: pytest.MonkeyPatch) -> Iterator[MagicMock directly and restore in teardown. """ import prisma as _prisma_pkg + import litellm.proxy.utils as _utils_mod fake_prisma = MagicMock(name="FakePrisma") diff --git a/tests/test_litellm/proxy/utils/proxy_logging/conftest.py b/tests/test_litellm/proxy/utils/proxy_logging/conftest.py index 74508a74e3b..32c269d7b21 100644 --- a/tests/test_litellm/proxy/utils/proxy_logging/conftest.py +++ b/tests/test_litellm/proxy/utils/proxy_logging/conftest.py @@ -6,16 +6,11 @@ live here. Tests should not declare fixtures inline. from __future__ import annotations -import sys -from pathlib import Path from typing import Any, Dict, Optional from unittest.mock import MagicMock import pytest -sys.path.insert(0, str(Path(__file__).resolve().parents[5])) - - VOLATILE_KEYS = frozenset( { "created_at", diff --git a/tests/test_litellm/test_chat_ui_responses_session.py b/tests/test_litellm/test_chat_ui_responses_session.py index 2f960d4e827..d4345de2462 100644 --- a/tests/test_litellm/test_chat_ui_responses_session.py +++ b/tests/test_litellm/test_chat_ui_responses_session.py @@ -9,13 +9,8 @@ Verifies that: import inspect import json -import os -import sys import unittest.mock as mock -# Use __file__ so the import path is correct regardless of the pytest working directory. -sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..")) - import httpx import pytest diff --git a/tests/test_litellm/test_check_licenses.py b/tests/test_litellm/test_check_licenses.py index 1218e44fade..948327bf8af 100644 --- a/tests/test_litellm/test_check_licenses.py +++ b/tests/test_litellm/test_check_licenses.py @@ -17,7 +17,7 @@ import requests _CODE_COVERAGE_DIR = os.path.join( os.path.dirname(os.path.abspath(__file__)), "..", "code_coverage_tests" ) -sys.path.insert(0, _CODE_COVERAGE_DIR) +sys.path.insert(0, _CODE_COVERAGE_DIR) # test-quality-ok: required to import checker from its source directory import check_licenses # noqa: E402 diff --git a/tests/test_litellm/test_completion_timeout_resolution.py b/tests/test_litellm/test_completion_timeout_resolution.py index 7eb79e90e60..45bd1ccf233 100644 --- a/tests/test_litellm/test_completion_timeout_resolution.py +++ b/tests/test_litellm/test_completion_timeout_resolution.py @@ -1,12 +1,7 @@ """Unit tests for litellm.litellm_core_utils.completion_timeout.CompletionTimeout.""" -import os -import sys - import httpx -sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../.."))) - from litellm.litellm_core_utils.completion_timeout import CompletionTimeout from litellm.utils import supports_httpx_timeout diff --git a/tests/test_litellm/test_nested_drop_params.py b/tests/test_litellm/test_nested_drop_params.py index bb1305ffde4..500db8624ca 100644 --- a/tests/test_litellm/test_nested_drop_params.py +++ b/tests/test_litellm/test_nested_drop_params.py @@ -4,13 +4,8 @@ Test nested path support in additional_drop_params. This tests the new JSONPath-like syntax for removing nested fields. """ -import os -import sys -# Add parent directory to path -sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))) - from litellm.litellm_core_utils.dot_notation_indexing import ( delete_nested_value, is_nested_path, diff --git a/tests/test_litellm/test_ssl_verify_unit.py b/tests/test_litellm/test_ssl_verify_unit.py index c39362c01a2..097ba279c68 100644 --- a/tests/test_litellm/test_ssl_verify_unit.py +++ b/tests/test_litellm/test_ssl_verify_unit.py @@ -5,15 +5,10 @@ These tests verify that ssl_verify parameters are correctly propagated through the call stack without requiring live API credentials. """ -import sys -from pathlib import Path from unittest.mock import Mock, patch import pytest -# Add litellm to path -sys.path.insert(0, str(Path(__file__).parent)) - import litellm.proxy.guardrails.guardrail_hooks.aim.aim as _aim_module import litellm.proxy.guardrails.guardrail_hooks.cato_networks.cato_networks as _cato_networks_module from litellm.llms.bedrock.base_aws_llm import BaseAWSLLM diff --git a/tests/test_litellm/test_vcr_safe_body_matcher.py b/tests/test_litellm/test_vcr_safe_body_matcher.py index 712ecf09911..1a6f2096a97 100644 --- a/tests/test_litellm/test_vcr_safe_body_matcher.py +++ b/tests/test_litellm/test_vcr_safe_body_matcher.py @@ -1,15 +1,9 @@ from __future__ import annotations -import os -import sys from types import SimpleNamespace import pytest -_REPO_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) -if _REPO_ROOT not in sys.path: - sys.path.insert(0, _REPO_ROOT) - from tests._vcr_conftest_common import ( # noqa: E402 KEY_FINGERPRINT_HEADER, KEY_FINGERPRINT_MATCHER_NAME,