From 009a2bd06b58f505daeacc7be310434acc98fe27 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Fri, 4 Sep 2026 19:22:09 -0700 Subject: [PATCH] test(bedrock_mantle): record mock requests with Mock instead of a mutable list --- .../test_bedrock_mantle_transformation.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tests/test_litellm/llms/bedrock_mantle/test_bedrock_mantle_transformation.py b/tests/test_litellm/llms/bedrock_mantle/test_bedrock_mantle_transformation.py index 8c8d29d103f..efe1a0b057a 100644 --- a/tests/test_litellm/llms/bedrock_mantle/test_bedrock_mantle_transformation.py +++ b/tests/test_litellm/llms/bedrock_mantle/test_bedrock_mantle_transformation.py @@ -6,7 +6,7 @@ API docs: https://docs.aws.amazon.com/bedrock/latest/userguide/bedrock-mantle.ht """ import json -from unittest.mock import patch +from unittest.mock import Mock, patch import httpx @@ -726,10 +726,7 @@ class TestBedrockMantleProviderResolution: monkeypatch.setenv("AWS_ACCESS_KEY_ID", "AKIAEXAMPLE") monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "c2VjcmV0LXRlc3Qtc2VjcmV0LXRlc3Qtc2VjcmV0") - requests = [] - - def handler(request: httpx.Request) -> httpx.Response: - requests.append(request) + def respond(request: httpx.Request) -> httpx.Response: return httpx.Response( status_code=200, json={ @@ -743,6 +740,7 @@ class TestBedrockMantleProviderResolution: request=request, ) + handler = Mock(side_effect=respond) response = litellm.completion( model="bedrock_mantle/us-gov-west-1/xai.grok-4.3", messages=[{"role": "user", "content": "hello"}], @@ -750,7 +748,7 @@ class TestBedrockMantleProviderResolution: ) gov = litellm.model_cost["bedrock_mantle/us-gov-west-1/xai.grok-4.3"] - sent = requests[0] + sent = handler.call_args.args[0] assert str(sent.url) == "https://bedrock-mantle.us-gov-west-1.api.aws/openai/v1/chat/completions" assert json.loads(sent.content)["model"] == "xai.grok-4.3" assert "/us-gov-west-1/bedrock/aws4_request" in sent.headers["Authorization"] @@ -774,10 +772,7 @@ class TestBedrockMantleProviderResolution: monkeypatch.setenv("AWS_ACCESS_KEY_ID", "AKIAEXAMPLE") monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "c2VjcmV0LXRlc3Qtc2VjcmV0LXRlc3Qtc2VjcmV0") - requests = [] - - def handler(request: httpx.Request) -> httpx.Response: - requests.append(request) + def respond(request: httpx.Request) -> httpx.Response: return httpx.Response( status_code=200, json={ @@ -804,6 +799,7 @@ class TestBedrockMantleProviderResolution: request=request, ) + handler = Mock(side_effect=respond) response = litellm.responses( model="bedrock_mantle/us-gov-west-1/xai.grok-4.3", input="hello", @@ -811,7 +807,7 @@ class TestBedrockMantleProviderResolution: ) gov = litellm.model_cost["bedrock_mantle/us-gov-west-1/xai.grok-4.3"] - sent = requests[0] + sent = handler.call_args.args[0] assert str(sent.url) == "https://bedrock-mantle.us-gov-west-1.api.aws/openai/v1/responses" assert json.loads(sent.content)["model"] == "xai.grok-4.3" assert "/us-gov-west-1/bedrock/aws4_request" in sent.headers["Authorization"]