test: escape the literal match= patterns this branch mints

This commit is contained in:
ryan-crabbe-berri 2026-08-21 16:22:07 -07:00
parent 6266b3d50a
commit 65249f25a3
6 changed files with 18 additions and 10 deletions

View file

@ -63,7 +63,7 @@ def test_container_files_api():
# 3. Try retrieve non-existent file metadata (should raise error)
print("3. Testing retrieve_container_file (expect error)...")
with pytest.raises(Exception, match="(?i)not found|invalid"):
with pytest.raises(Exception, match=r"(?i)not found|invalid"):
retrieve_container_file(
container_id=container.id,
file_id="cfile_nonexistent",

View file

@ -1,5 +1,6 @@
import json
import os
import re
import sys
from datetime import datetime
from io import BytesIO
@ -578,7 +579,7 @@ def test_litellm_gateway_from_sdk_with_response_cost_in_additional_headers():
def test_litellm_gateway_from_sdk_with_thinking_param():
with pytest.raises(Exception, match="Connection error.") as exc_info:
with pytest.raises(Exception, match=re.escape("Connection error.")) as exc_info:
response = litellm.completion(
model="litellm_proxy/anthropic.claude-sonnet-4-5-20250929-v1:0",
messages=[{"role": "user", "content": "Hello world"}],

View file

@ -2,6 +2,7 @@
# This tests setting rules before / after making llm api calls
import asyncio
import os
import re
import sys
import time
import traceback
@ -82,7 +83,7 @@ def test_post_call_rule():
litellm.post_call_rules = [my_post_call_rule]
### completion
with pytest.raises(Exception, match="This violates LiteLLM Proxy Rules. Response too short") as exc_info:
with pytest.raises(Exception, match=re.escape("This violates LiteLLM Proxy Rules. Response too short")) as exc_info:
completion(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "say sorry"}],
@ -118,7 +119,7 @@ def test_post_call_rule_streaming():
stream=True,
)
with pytest.raises(Exception, match="This violates LiteLLM Proxy Rules. Response too short") as exc_info:
with pytest.raises(Exception, match=re.escape("This violates LiteLLM Proxy Rules. Response too short")) as exc_info:
list(response)
assert "This violates LiteLLM Proxy Rules. Response too short" in exc_info.value.message

View file

@ -3,6 +3,7 @@ RBAC tests
"""
import os
import re
import sys
import traceback
from litellm._uuid import uuid
@ -411,7 +412,7 @@ async def test_org_admin_create_user_team_wrong_org_permissions(prisma_client):
request.body = return_body
with pytest.raises(
Exception, match="You do not have a role within the selected organization. Passed organization_id"
Exception, match=re.escape("You do not have a role within the selected organization. Passed organization_id")
) as exc_info:
response = await user_api_key_auth(request=request, api_key="Bearer " + new_key)
e = exc_info.value

View file

@ -20,6 +20,7 @@
# function to validate a request - async def user_auth(request: Request):
import os
import re
import sys
import traceback
from litellm._uuid import uuid
@ -1498,7 +1499,9 @@ def test_key_generate_with_custom_auth(prisma_client):
await litellm.proxy.proxy_server.prisma_client.connect()
request = GenerateKeyRequest()
with pytest.raises(Exception, match="This violates LiteLLM Proxy Rules. No team id provided.") as exc_info:
with pytest.raises(
Exception, match=re.escape("This violates LiteLLM Proxy Rules. No team id provided.")
) as exc_info:
key = await generate_key_fn(
request,
user_api_key_dict=UserAPIKeyAuth(
@ -3045,7 +3048,9 @@ async def test_custom_api_key_header_name(prisma_client):
"headers": [],
}
)
with pytest.raises(Exception, match="Malformed API Key passed in. Ensure Key has `Bearer ` prefix") as exc_info:
with pytest.raises(
Exception, match=re.escape("Malformed API Key passed in. Ensure Key has `Bearer ` prefix")
) as exc_info:
result = await user_api_key_auth(request=request, api_key="Bearer sk-1234")
e = exc_info.value
print("failed with error", e)

View file

@ -3025,7 +3025,7 @@ def test_request_metadata_key_constraints():
long_key = "a" * 257
invalid_metadata = {long_key: "value"}
with pytest.raises(Exception, match="(?i)key length|256 characters"):
with pytest.raises(Exception, match=r"(?i)key length|256 characters"):
config.transform_request(
model="anthropic.claude-haiku-4-5-20251001-v1:0",
messages=messages,
@ -3037,7 +3037,7 @@ def test_request_metadata_key_constraints():
# Test empty key
invalid_metadata = {"": "value"}
with pytest.raises(Exception, match="(?i)key length|empty"):
with pytest.raises(Exception, match=r"(?i)key length|empty"):
config.transform_request(
model="anthropic.claude-haiku-4-5-20251001-v1:0",
messages=messages,
@ -3057,7 +3057,7 @@ def test_request_metadata_value_constraints():
long_value = "a" * 257
invalid_metadata = {"key": long_value}
with pytest.raises(Exception, match="(?i)value length|256 characters"):
with pytest.raises(Exception, match=r"(?i)value length|256 characters"):
config.transform_request(
model="anthropic.claude-haiku-4-5-20251001-v1:0",
messages=messages,