diff --git a/tests/llm_translation/test_containers_api.py b/tests/llm_translation/test_containers_api.py index 6c7303e7b4d..7fb0c6d21d6 100644 --- a/tests/llm_translation/test_containers_api.py +++ b/tests/llm_translation/test_containers_api.py @@ -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", diff --git a/tests/llm_translation/test_litellm_proxy_provider.py b/tests/llm_translation/test_litellm_proxy_provider.py index cea0167472e..7a917c226df 100644 --- a/tests/llm_translation/test_litellm_proxy_provider.py +++ b/tests/llm_translation/test_litellm_proxy_provider.py @@ -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"}], diff --git a/tests/local_testing/test_rules.py b/tests/local_testing/test_rules.py index b075821e205..7ffab789d64 100644 --- a/tests/local_testing/test_rules.py +++ b/tests/local_testing/test_rules.py @@ -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 diff --git a/tests/proxy_admin_ui_tests/test_role_based_access.py b/tests/proxy_admin_ui_tests/test_role_based_access.py index b5a076d0185..1c4ee2caa04 100644 --- a/tests/proxy_admin_ui_tests/test_role_based_access.py +++ b/tests/proxy_admin_ui_tests/test_role_based_access.py @@ -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 diff --git a/tests/proxy_unit_tests/test_key_generate_prisma.py b/tests/proxy_unit_tests/test_key_generate_prisma.py index 16507aaaf55..efedc156429 100644 --- a/tests/proxy_unit_tests/test_key_generate_prisma.py +++ b/tests/proxy_unit_tests/test_key_generate_prisma.py @@ -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) diff --git a/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py b/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py index 30843e8160b..a2f88138eaa 100644 --- a/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py +++ b/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py @@ -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,