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: wrap the raising call, not the print that follows it
ryan-crabbe-berri4d8346a5b9f7
diff --git a/tests/local_testing/test_exceptions.py b/tests/local_testing/test_exceptions.pyindex e0117e1fe0d..cf89e7bea1d 100644--- a/tests/local_testing/test_exceptions.py+++ b/tests/local_testing/test_exceptions.py@@ -441,26 +441,16 @@ def test_completion_bedrock_invalid_role_exception():Test if litellm raises a BadRequestError for an invalid role on Bedrock"""litellm.set_verbose = True- response = completion(- model="bedrock/anthropic.claude-3-sonnet-20240229-v1:0",- messages=[{"role": "very-bad-role", "content": "hello"}],- )- print(f"response: {response}")-with pytest.raises(litellm.BadRequestError) as exc_info:- print(response)- e = exc_info.value- assert isinstance(- e, litellm.BadRequestError- ), "Expected BadRequestError but got {}".format(type(e))- print("str(e) = {}".format(str(e)))+ completion(+ model="bedrock/anthropic.claude-3-sonnet-20240229-v1:0",+ messages=[{"role": "very-bad-role", "content": "hello"}],+ )# This is important - We we previously returning a poorly formatted error string. Which was# litellm.BadRequestError: litellm.BadRequestError: Invalid Message passed in {'role': 'very-bad-role', 'content': 'hello'}-- # IMPORTANT ASSERTIONassert (- (str(e))+ str(exc_info.value)== "litellm.BadRequestError: Invalid Message passed in {'role': 'very-bad-role', 'content': 'hello'}")diff --git a/tests/local_testing/test_router_fallbacks.py b/tests/local_testing/test_router_fallbacks.pyindex f9ec69c1a57..1cafd2c709d 100644--- a/tests/local_testing/test_router_fallbacks.py+++ b/tests/local_testing/test_router_fallbacks.py@@ -1197,22 +1197,19 @@ async def test_using_default_fallback(sync_mode):},],)- if sync_mode:- response = router.completion(- model="openai/foo",- messages=[{"role": "user", "content": "Hey, how's it going?"}],- )- else:- response = await router.acompletion(+ async def call_router():+ if sync_mode:+ return router.completion(+ model="openai/foo",+ messages=[{"role": "user", "content": "Hey, how's it going?"}],+ )+ return await router.acompletion(model="openai/foo",messages=[{"role": "user", "content": "Hey, how's it going?"}],)- with pytest.raises(Exception, match="BadRequestError") as exc_info:- print("got response=", response)- e = exc_info.value- print("got exception = ", e)- assert "BadRequestError" in str(e)+ with pytest.raises(Exception, match="BadRequestError"):+ await call_router()@pytest.mark.parametrize("sync_mode", [False])diff --git a/tests/proxy_admin_ui_tests/test_key_management.py b/tests/proxy_admin_ui_tests/test_key_management.pyindex d7bba09e6a1..9fff120bba1 100644--- a/tests/proxy_admin_ui_tests/test_key_management.py+++ b/tests/proxy_admin_ui_tests/test_key_management.py@@ -197,15 +197,9 @@ async def test_regenerate_api_key(prisma_client):return return_string.encode()request.body = return_body_3- result = await user_api_key_auth(- request=request, api_key=f"Bearer {generated_key}"- )-with pytest.raises(Exception, match="Invalid proxy server token passed") as exc_info:- print(result)- e = exc_info.value- print("got expected exception", e)- assert "Invalid proxy server token passed" in e.message+ await user_api_key_auth(request=request, api_key=f"Bearer {generated_key}")+ assert "Invalid proxy server token passed" in exc_info.value.message# Check that the regenerated key has the same spend, max_budget, models and key_aliasassert new_key.spend == spend, f"Expected spend {spend} but got {new_key.spend}"diff --git a/tests/proxy_unit_tests/test_key_generate_prisma.py b/tests/proxy_unit_tests/test_key_generate_prisma.pyindex e10d6be4427..16507aaaf55 100644--- a/tests/proxy_unit_tests/test_key_generate_prisma.py+++ b/tests/proxy_unit_tests/test_key_generate_prisma.py@@ -2079,17 +2079,10 @@ async def test_call_with_key_over_budget_stream(prisma_client):proxy_logging_obj=proxy_logging_obj,)# use generated key to auth in- result = await user_api_key_auth(request=request, api_key=bearer_token)-with pytest.raises(Exception, match="Budget has been exceeded") as exc_info:- print("result from user auth with new key", result)- e = exc_info.value- print("Got Exception", e)+ await user_api_key_auth(request=request, api_key=bearer_token)# Handle DataError and other exceptions that don't have .message attribute- error_detail = getattr(e, "message", str(e))- assert "Budget has been exceeded" in error_detail-- print(vars(e))+ assert "Budget has been exceeded" in getattr(exc_info.value, "message", str(exc_info.value))@pytest.mark.skip(reason="Requires reliable external DB connection (prisma).")