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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test: fix stale and state-leaking tests red on scheduled CircleCI (#43266)
yuneng-jiang7fc220617154
diff --git a/.circleci/config.yml b/.circleci/config.ymlindex 370424dca86..3ff8061fb48 100644--- a/.circleci/config.yml+++ b/.circleci/config.yml@@ -323,6 +323,7 @@ jobs:CHOCOLATEY_CONFIRM_ALL: "true"- run:name: Install Dependencies+ no_output_timeout: 30menvironment:UV_HTTP_TIMEOUT: "300"command: |@@ -381,6 +382,7 @@ jobs:uv run --no-sync python -m pytest tests/windows_tests/ -v- run:name: Guard against MAX_PATH-busting packaged wheel paths+ no_output_timeout: 30menvironment:UV_HTTP_TIMEOUT: "300"command: |diff --git a/tests/local_testing/conftest.py b/tests/local_testing/conftest.pyindex d03f074f557..df3dacac3b2 100644--- a/tests/local_testing/conftest.py+++ b/tests/local_testing/conftest.py@@ -19,6 +19,7 @@ import pytestimport litellmfrom litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER+from litellm.utils import _invalidate_model_cost_lowercase_map# ``litellm.model_cost`` is loaded at import time from the URL pinned to ``main``# (``LITELLM_MODEL_COST_MAP_URL``). The in-tree backup ships with this branch@@ -232,6 +233,7 @@ def isolate_litellm_state():for attr, original_value in original_state.items():if hasattr(litellm, attr):setattr(litellm, attr, original_value)+ _invalidate_model_cost_lowercase_map()@pytest.fixture(scope="module", autouse=True)diff --git a/tests/local_testing/test_get_model_info.py b/tests/local_testing/test_get_model_info.pyindex 1e46a1bf853..dbe1fc3b69b 100644--- a/tests/local_testing/test_get_model_info.py+++ b/tests/local_testing/test_get_model_info.py@@ -9,6 +9,7 @@ import pytestimport litellmfrom litellm import get_model_info+from litellm.utils import _invalidate_model_cost_lowercase_mapfrom unittest.mock import MagicMock, patch@@ -74,15 +75,15 @@ def test_get_model_info_ollama_chat():assert mock_client.call_args.kwargs["json"]["name"] == "unknown-model"-def test_get_model_info_bedrock_region():- os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"- litellm.model_cost = litellm.get_model_cost_map(url="")- args = {- "model": "us.anthropic.claude-haiku-4-5-20251001-v1:0",- "custom_llm_provider": "bedrock",+def test_get_model_info_bedrock_region(monkeypatch):+ regional_model = "us.anthropic.claude-haiku-4-5-20251001-v1:0"+ monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True")+ model_cost_without_regional_entry = {+ key: value for key, value in litellm.get_model_cost_map(url="").items() if key != regional_model}- litellm.model_cost.pop("us.anthropic.claude-haiku-4-5-20251001-v1:0", None)- info = litellm.get_model_info(**args)+ monkeypatch.setattr(litellm, "model_cost", model_cost_without_regional_entry)+ _invalidate_model_cost_lowercase_map()+ info = litellm.get_model_info(model=regional_model, custom_llm_provider="bedrock")print("info", info)assert info["key"] == "anthropic.claude-haiku-4-5-20251001-v1:0"assert info["litellm_provider"] == "bedrock_converse"diff --git a/tests/test_rust_python_harness.py b/tests/test_rust_python_harness.pyindex a1bb370a074..9af38941684 100644--- a/tests/test_rust_python_harness.py+++ b/tests/test_rust_python_harness.py@@ -36,8 +36,6 @@ def _case(module: str = "tests.example") -> HarnessCase:@pytest.mark.parametrize("module",[- "tests.rust-python-harness.strategies.e2e_parity.sdk.ocr.test_sdk_parity",- "tests.rust-python-harness.strategies.trace_parity.sdk.ocr.case","tests.rust-python-harness.strategies.trace_parity.sdk.messages.case","tests.rust-python-harness.strategies.trace_parity.sdk.chat_completions.case","tests.rust-python-harness.strategies.trace_parity.sdk.transcription.case",diff --git a/tests/unit/enterprise/enterprise_callbacks/test_prometheus_logging_callbacks.py b/tests/unit/enterprise/enterprise_callbacks/test_prometheus_logging_callbacks.pyindex 92ff3d5813c..f1c80bb11ea 100644--- a/tests/unit/enterprise/enterprise_callbacks/test_prometheus_logging_callbacks.py+++ b/tests/unit/enterprise/enterprise_callbacks/test_prometheus_logging_callbacks.py@@ -1,7 +1,6 @@import asyncio-import loggingfrom datetime import datetime, timedelta, timezonefrom unittest.mock import MagicMock, call, patch@@ -9,7 +8,6 @@ import pytestfrom prometheus_client import REGISTRYimport litellm-from litellm._logging import verbose_loggerfrom litellm.types.utils import (StandardLoggingHiddenParams,StandardLoggingMetadata,@@ -27,10 +25,6 @@ except Exception:PrometheusLogger = Nonefrom litellm.proxy._types import UserAPIKeyAuth-verbose_logger.setLevel(logging.DEBUG)--litellm.set_verbose = True-@pytest.fixturedef prometheus_logger() -> PrometheusLogger:diff --git a/tests/unit/proxy/test_proxy_server.py b/tests/unit/proxy/test_proxy_server.pyindex eae80f311d8..65b368ca9e3 100644--- a/tests/unit/proxy/test_proxy_server.py+++ b/tests/unit/proxy/test_proxy_server.py@@ -2979,7 +2979,7 @@ async def test_get_config_callbacks_environment_variables(client_no_auth):@pytest.mark.asyncio-async def test_update_config_success_callback_normalization():+async def test_update_config_success_callback_normalization(monkeypatch):"""Ensure success_callback values are normalized to lowercase when updating config.This prevents delete_callback (which searches lowercase) from failing on mixed case inputs like 'SQS'.@@ -2987,7 +2987,7 @@ async def test_update_config_success_callback_normalization():import litellm.proxy.proxy_server as proxy_serverfrom litellm.proxy._types import ConfigYAML- setattr(proxy_server, "proxy_logging_obj", MagicMock())+ monkeypatch.setattr(proxy_server, "proxy_logging_obj", MagicMock())existing_litellm_settings = {"success_callback": ["langfuse"]}@@ -3013,7 +3013,7 @@ async def test_update_config_success_callback_normalization():self.db.litellm_config.find_first = AsyncMock(side_effect=fake_find_first)self.db.litellm_config.upsert = AsyncMock(side_effect=fake_upsert)- setattr(proxy_server, "prisma_client", MockPrisma())+ monkeypatch.setattr(proxy_server, "prisma_client", MockPrisma())class MockProxyConfig:async def add_deployment(self, prisma_client=None, proxy_logging_obj=None): # noqa: F811 # pytest fixture, not a redefinition@@ -3022,7 +3022,7 @@ async def test_update_config_success_callback_normalization():def reject_config_owned_writes(self, *, section_name, changed_keys):return None- setattr(proxy_server, "proxy_config", MockProxyConfig())+ monkeypatch.setattr(proxy_server, "proxy_config", MockProxyConfig())config_update = ConfigYAML(litellm_settings={"success_callback": ["SQS", "sQs"]})from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth