diff --git a/tests/lib/test_aws.py b/tests/lib/test_aws.py index a571f85cf..377fdc3aa 100644 --- a/tests/lib/test_aws.py +++ b/tests/lib/test_aws.py @@ -135,6 +135,13 @@ def _clear_aws_url_env(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.delenv(var, raising=False) +@pytest.fixture(autouse=True) +def isolate_env(monkeypatch: pytest.MonkeyPatch) -> None: + """Keep AWS settings from the developer's shell out of these tests.""" + _clear_aws_url_env(monkeypatch) + monkeypatch.delenv("ANTHROPIC_AWS_API_KEY", raising=False) + + def _set_ambient_first_party_credentials(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setenv("ANTHROPIC_API_KEY", "ambient-key") monkeypatch.setenv("ANTHROPIC_AUTH_TOKEN", "ambient-token") diff --git a/tests/lib/test_aws_auth.py b/tests/lib/test_aws_auth.py index e0e95fcf7..29a22902b 100644 --- a/tests/lib/test_aws_auth.py +++ b/tests/lib/test_aws_auth.py @@ -15,6 +15,22 @@ validate_credentials, ) + +@pytest.fixture(autouse=True) +def isolate_env(monkeypatch: pytest.MonkeyPatch) -> None: + """Keep AWS settings from the developer's shell out of these tests.""" + for name in ( + "AWS_REGION", + "AWS_DEFAULT_REGION", + "AWS_PROFILE", + "AWS_BEARER_TOKEN_BEDROCK", + "ANTHROPIC_AWS_API_KEY", + "ANTHROPIC_AWS_BASE_URL", + "ANTHROPIC_AWS_WORKSPACE_ID", + ): + monkeypatch.delenv(name, raising=False) + + # --- validate_credentials --- diff --git a/tests/lib/test_bedrock_mantle.py b/tests/lib/test_bedrock_mantle.py index 6aa1bb393..34c09a0fe 100644 --- a/tests/lib/test_bedrock_mantle.py +++ b/tests/lib/test_bedrock_mantle.py @@ -18,6 +18,20 @@ MODEL = "anthropic.claude-sonnet-4-5" +@pytest.fixture(autouse=True) +def isolate_env(monkeypatch: pytest.MonkeyPatch) -> None: + """Keep AWS settings from the developer's shell out of these tests.""" + for name in ( + "AWS_REGION", + "AWS_DEFAULT_REGION", + "AWS_PROFILE", + "AWS_BEARER_TOKEN_BEDROCK", + "ANTHROPIC_AWS_API_KEY", + "ANTHROPIC_BEDROCK_MANTLE_BASE_URL", + ): + monkeypatch.delenv(name, raising=False) + + class GetAuthHeadersRecorder: """Stands in for `anthropic.lib.bedrock._mantle.get_auth_headers` and records each call's kwargs."""