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(bedrock): isolate host AWS config in realtime and rerank unit tests

yunengfeca00248cf7
diff --git a/tests/unit/llms/bedrock/realtime/test_bedrock_realtime_handler.py b/tests/unit/llms/bedrock/realtime/test_bedrock_realtime_handler.py
index a7f0f64ef68..73a78a94e9f 100644
--- a/tests/unit/llms/bedrock/realtime/test_bedrock_realtime_handler.py
+++ b/tests/unit/llms/bedrock/realtime/test_bedrock_realtime_handler.py
@@ -18,6 +18,15 @@ from litellm.llms.bedrock.realtime.handler import BedrockRealtime
from litellm.llms.bedrock.realtime.transformation import BedrockRealtimeConfig
[email protected](autouse=True)
+def _isolate_host_aws_config(monkeypatch, tmp_path):
+ monkeypatch.setenv("AWS_SHARED_CREDENTIALS_FILE", str(tmp_path / "credentials"))
+ monkeypatch.setenv("AWS_CONFIG_FILE", str(tmp_path / "config"))
+ monkeypatch.setenv("AWS_EC2_METADATA_DISABLED", "true")
+ for env_var in ("AWS_PROFILE", "AWS_DEFAULT_PROFILE", "AWS_BEARER_TOKEN_BEDROCK", "AWS_REGION_NAME", "AWS_DEFAULT_REGION"):
+ monkeypatch.delenv(env_var, raising=False)
+
+
class FakePayloadPart:
def __init__(self, bytes_):
self.bytes_ = bytes_
diff --git a/tests/unit/llms/bedrock/rerank/test_bedrock_rerank_header_forwarding.py b/tests/unit/llms/bedrock/rerank/test_bedrock_rerank_header_forwarding.py
index 2ea61b5e978..aa93ddb21b8 100644
--- a/tests/unit/llms/bedrock/rerank/test_bedrock_rerank_header_forwarding.py
+++ b/tests/unit/llms/bedrock/rerank/test_bedrock_rerank_header_forwarding.py
@@ -15,6 +15,15 @@ from litellm.llms.bedrock.base_aws_llm import Boto3CredentialsInfo
from litellm.llms.bedrock.rerank.handler import BedrockRerankHandler
from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandler
+
[email protected](autouse=True)
+def _isolate_host_aws_config(monkeypatch, tmp_path):
+ monkeypatch.setenv("AWS_SHARED_CREDENTIALS_FILE", str(tmp_path / "credentials"))
+ monkeypatch.setenv("AWS_CONFIG_FILE", str(tmp_path / "config"))
+ monkeypatch.setenv("AWS_EC2_METADATA_DISABLED", "true")
+ for env_var in ("AWS_PROFILE", "AWS_DEFAULT_PROFILE", "AWS_BEARER_TOKEN_BEDROCK", "AWS_REGION_NAME", "AWS_DEFAULT_REGION"):
+ monkeypatch.delenv(env_var, raising=False)
+
# Mock response for Bedrock rerank
# Format based on Bedrock rerank API response structure
bedrock_rerank_response = {