Repository navigation
chore(tests): clear ANTHROPIC_BASE_URL in the credential tests' env isolation - #2021
alphasafal wants to merge 1 commit into
Conversation
chrikrah
left a comment
There was a problem hiding this comment.
@alphasafal this is right as it stands at 941c0a1. Your before counts reproduce in a clean environment (after, I get 292 passed against your 291), and fill(config, "base_url", ENV_BASE_URL) at _providers.py:101 is the read that leaks the shell value into the profile.
$ env -i HOME=<empty> ANTHROPIC_BASE_URL=https://gateway.example python -m pytest tests/lib/test_credentials.py -q -n 4
2a53eaa (base): 49 failed, 243 passed, 2 skipped, 48 errors
941c0a1: 292 passed, 2 skipped
$ env -i HOME=<empty> ANTHROPIC_BASE_URL=https://api.anthropic.com python -m pytest tests/lib/test_credentials.py -q -n 4 # 2a53eaa
4 failed, 288 passed, 2 skipped, 3 errors
$ env -i HOME=<empty> ANTHROPIC_BASE_URL=https://gateway.example python -m pytest tests/lib -q -n 4 # 941c0a1
2161 passed, 10 skipped, 1 xfailed
non-blocking: the list missed ANTHROPIC_BASE_URL from the start. Building it from the module keeps it in step with _constants.py:
from anthropic.lib.credentials import _constants as _credential_constants
_ALL_ENV = [v for k, v in vars(_credential_constants).items() if k.startswith("ENV_")]That yields the same 12 names, and the file gives 292 passed, 2 skipped with the gateway variable set. The list came from 3be1e89 without BASE_URL, and 119e123 later added WORKSPACE_ID to both files by hand.
@dtmeadows-ant I'd merge the one-line version now and leave the derived list as a follow-up, since it touches nothing outside the test file. Is that fine on your side?
|
Thanks for reproducing it, @chrikrah. Your clean-env counts are the ones to go by; I'll use Checking the rest of |
_ALL_ENVintests/lib/test_credentials.pyis meant to mirror theENV_*constants inlib/credentials/_constants.py, but it's missingANTHROPIC_BASE_URL.CredentialsFilefills a profile's missingbase_urlfrom that variable, so if it's set in your shell (e.g. behind a gateway), token exchanges go to your host instead of the one the tests mock.Running
tests/lib/test_credentials.pywithANTHROPIC_BASE_URL=https://gateway.example:It also breaks 4 tests when set to
https://api.anthropic.com. This only changes the tests, so runtime behaviour is untouched. The fulltests/libsuite passes with the variable set, and ruff and pyright are clean.