Skip to content

chore(tests): clear ambient AWS env vars in the Mantle and AWS client tests - #2030

Open
alphasafal wants to merge 3 commits into
anthropics:mainfrom
alphasafal:patch-2
Open

alphasafal wants to merge 3 commits into
anthropics:mainfrom
alphasafal:patch-2

Conversation

@alphasafal

Copy link
Copy Markdown

Same kind of leak as #2021, in the AWS-side tests.

tests/lib/test_bedrock_mantle.py, test_aws.py and test_aws_auth.py don't clear the environment for every test, so AWS settings exported in your shell reach the clients under test. With ANTHROPIC_BEDROCK_MANTLE_BASE_URL set (e.g. behind a gateway), Mantle requests go to that host instead of the URL the tests mock, and AWS_PROFILE, AWS_REGION/AWS_DEFAULT_REGION and the API-key variables change the region and auth mode the clients resolve.

This adds an autouse fixture to each file that clears the variables those clients read. In test_aws.py it reuses the existing _clear_aws_url_env helper, so there's no second list there. I left the explicit _clear_aws_url_env(...) calls in place to keep the diff small; happy to drop them if you'd prefer.

Running the three files with one variable set at a time:

$ env -i HOME=<empty> VAR=... python -m pytest tests/lib/test_bedrock_mantle.py tests/lib/test_aws.py tests/lib/test_aws_auth.py -q -n 2
Variable main this PR
(none) 228 passed 228 passed
ANTHROPIC_BEDROCK_MANTLE_BASE_URL 49 failed, 44 errors 228 passed
ANTHROPIC_AWS_BASE_URL 16 failed, 13 errors 228 passed
AWS_PROFILE 14 failed, 6 errors 228 passed
AWS_DEFAULT_REGION 4 failed 228 passed
AWS_REGION 2 failed 228 passed
AWS_BEARER_TOKEN_BEDROCK 1 failed 228 passed
ANTHROPIC_AWS_API_KEY 1 failed 228 passed

This only changes the tests, so runtime behaviour is untouched. The full tests/lib suite passes (2462 passed, 20 skipped, 1 xfailed) and ./scripts/lint is clean.

test_bedrock.py and test_vertex.py have the same leak, but they build their clients at import time (module-level and class attributes), so a fixture can't reach them. That needs a separate change.

Copilot AI balanced review requested due to automatic review settings October 22, 2026 03:29
@alphasafal
alphasafal requested a review from a team as a code owner October 22, 2026 03:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants