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: gate the test suite on F601, B023, B025 and F632

ryan-crabbe-berrib7f8016002c0
diff --git a/ruff-tests.toml b/ruff-tests.toml
index de0931f5e69..8f21ca31a6f 100644
--- a/ruff-tests.toml
+++ b/ruff-tests.toml
@@ -36,6 +36,17 @@
# `re.search`, so a `.` copied out of an error message is a wildcard and the block
# accepts messages the author never meant to accept. Mark a real regex raw, wrap a
# literal message in `re.escape`, and the pattern says which one it is
+# F601 the same key literal twice in one dict. Python keeps the last value, so the
+# first is dropped before the test ever runs, and a fixture that looks like it
+# covers two cases covers one
+# B023 a closure over a loop variable. Every closure sees the last iteration's value,
+# so a per-case callback built in a loop checks the last case N times. Bind the
+# value as a parameter instead
+# B025 an `except` for a type an earlier `except` already catches. The second handler
+# is unreachable, so the recovery or skip written there never happens
+# F632 `is` against a literal. It compares identity, so it passes only where CPython
+# happens to intern the value and stops meaning what it says the moment the
+# value is built at runtime
#
# 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
@@ -58,4 +69,8 @@ lint.select = [
"PLR0133",
"PLW0127",
"RUF043",
+ "F601",
+ "B023",
+ "B025",
+ "F632",
]
diff --git a/tests/code_coverage_tests/bedrock_pricing.py b/tests/code_coverage_tests/bedrock_pricing.py
index b2c9e78b06c..e6219109f6d 100644
--- a/tests/code_coverage_tests/bedrock_pricing.py
+++ b/tests/code_coverage_tests/bedrock_pricing.py
@@ -95,7 +95,7 @@ def get_bedrock_pricing(url, providers):
else:
# General logic for other providers
section = soup.find(
- "h2", text=lambda t: t and provider.lower() in t.lower()
+ "h2", text=lambda t, needle=provider.lower(): t and needle in t.lower()
)
if not section:
pricing_data[provider] = "Provider section not found"
diff --git a/tests/load_tests/test_langsmith_load_test.py b/tests/load_tests/test_langsmith_load_test.py
index cf9fe526b74..40b976541a5 100644
--- a/tests/load_tests/test_langsmith_load_test.py
+++ b/tests/load_tests/test_langsmith_load_test.py
@@ -66,11 +66,6 @@ def test_langsmith_logging_async():
except Exception as e:
pytest.fail(f"An exception occurred - {e}")
- except litellm.Timeout as e:
- pass
- except Exception as e:
- pytest.fail(f"An exception occurred - {e}")
-
async def make_async_calls(metadata=None, **completion_kwargs):
total_tasks = 300
diff --git a/tests/local_testing/test_amazing_vertex_completion.py b/tests/local_testing/test_amazing_vertex_completion.py
index a52b5975f6e..53b3b2d6071 100644
--- a/tests/local_testing/test_amazing_vertex_completion.py
+++ b/tests/local_testing/test_amazing_vertex_completion.py
@@ -4207,13 +4207,7 @@ def test_gemini_google_maps_tool_simple():
)
print(f"Response: {response.model_dump_json(indent=4)}")
assert response.choices[0].message.content is not None
- except (litellm.RateLimitError, litellm.InternalServerError):
- # Transient Vertex-side failures (rate limiting, 500 INTERNAL from the
- # Google Maps grounding backend) are not LiteLLM bugs — don't fail CI.
- pass
- except litellm.InternalServerError:
- pytest.skip(
- "Google Maps Platform returned a transient 500 (upstream flake); skipping."
- )
+ except (litellm.RateLimitError, litellm.InternalServerError) as e:
+ pytest.skip(f"Transient Vertex-side failure, not a LiteLLM bug: {e}")
except Exception as e:
pytest.fail(f"Error occurred: {e}")
diff --git a/tests/logging_callback_tests/test_spend_logs.py b/tests/logging_callback_tests/test_spend_logs.py
index 709aa81f421..3aa0b3ebd90 100644
--- a/tests/logging_callback_tests/test_spend_logs.py
+++ b/tests/logging_callback_tests/test_spend_logs.py
@@ -148,7 +148,6 @@ def test_spend_logs_payload(model_id: Optional[str]):
"completion_start_time": datetime.datetime(2024, 6, 7, 12, 43, 30, 954146),
"max_tokens": 10,
"extra_body": {},
- "custom_llm_provider": "azure",
"input": [
{"role": "system", "content": "you are a helpful assistant.\n"},
{"role": "user", "content": "bom dia"},
diff --git a/tests/proxy_unit_tests/test_key_generate_prisma.py b/tests/proxy_unit_tests/test_key_generate_prisma.py
index efedc156429..4037107c474 100644
--- a/tests/proxy_unit_tests/test_key_generate_prisma.py
+++ b/tests/proxy_unit_tests/test_key_generate_prisma.py
@@ -3327,16 +3327,17 @@ async def test_team_access_groups(prisma_client):
request._url = URL(url="/chat/completions")
+ def body_reader(requested_model: str):
+ async def return_body() -> bytes:
+ return f'{{"model": "{requested_model}"}}'.encode()
+
+ return return_body
+
for model in ["gpt-4o", "gemini-pro-vision"]:
# Expect these to pass
- async def return_body():
- return_string = f'{{"model": "{model}"}}'
- # return string as bytes
- return return_string.encode()
-
request = Request(scope={"type": "http"})
request._url = URL(url="/chat/completions")
- request.body = return_body
+ request.body = body_reader(model)
# use generated key to auth in
print(
@@ -3346,14 +3347,9 @@ async def test_team_access_groups(prisma_client):
for model in ["gpt-4", "gpt-4o-mini", "gemini-experimental"]:
# Expect these to fail
- async def return_body_2():
- return_string = f'{{"model": "{model}"}}'
- # return string as bytes
- return return_string.encode()
-
request = Request(scope={"type": "http"})
request._url = URL(url="/chat/completions")
- request.body = return_body_2
+ request.body = body_reader(model)
# use generated key to auth in
print(
diff --git a/tests/test_litellm/llms/ollama/test_ollama_completion_transformation.py b/tests/test_litellm/llms/ollama/test_ollama_completion_transformation.py
index dd59cdcac1c..e746c1bfd6b 100644
--- a/tests/test_litellm/llms/ollama/test_ollama_completion_transformation.py
+++ b/tests/test_litellm/llms/ollama/test_ollama_completion_transformation.py
@@ -480,7 +480,7 @@ class TestOllamaTextCompletionResponseIterator:
assert isinstance(result, ModelResponseStream)
assert result.choices and result.choices[0].delta is not None
assert result.choices[0].delta.content == None
- assert getattr(result.choices[0].delta, "reasoning_content", None) is ""
+ assert getattr(result.choices[0].delta, "reasoning_content", None) == ""
def test_chunk_parser_done_chunk(self):
"""Test that done chunks work correctly."""
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 be74dc40eda..0f3a6bae1ff 100644
--- a/tests/test_litellm/llms/watsonx/test_watsonx_common_utils.py
+++ b/tests/test_litellm/llms/watsonx/test_watsonx_common_utils.py
@@ -129,11 +129,7 @@ class TestGenerateIAMToken:
mock_client.reset_mock()
mock_cache.reset_mock()
- # Configure mock to return values based on env_keys
- def get_secret_side_effect(key):
- return env_keys.get(key)
-
- mock_get_secret_str.side_effect = get_secret_side_effect
+ mock_get_secret_str.side_effect = env_keys.get
mock_response = MagicMock()
mock_response.json.return_value = {
diff --git a/tests/test_litellm/test_utils.py b/tests/test_litellm/test_utils.py
index bd23ca11fbe..a01540c51e8 100644
--- a/tests/test_litellm/test_utils.py
+++ b/tests/test_litellm/test_utils.py
@@ -864,7 +864,6 @@ def test_aaamodel_prices_and_context_window_json_is_valid():
"input_cost_per_character_above_128k_tokens": {"type": "number"},
"input_cost_per_image": {"type": "number"},
"input_cost_per_image_above_128k_tokens": {"type": "number"},
- "input_cost_per_image_token": {"type": "number"},
"input_cost_per_video_token": {"type": "number"},
"input_cost_per_token_above_200k_tokens": {"type": "number"},
"input_cost_per_token_above_256k_tokens": {"type": "number"},
@@ -1008,7 +1007,6 @@ def test_aaamodel_prices_and_context_window_json_is_valid():
},
"bedrock_converse_supports_strict_tools": {"type": "boolean"},
"tpm": {"type": "number"},
- "provider_specific_entry": {"type": "object"},
"supported_endpoints": {
"type": "array",
"items": {