Skip to content

The agent engineering platform.

test(anthropic): make tests robust to gateway base URL (#38043)

Mason Daughertyf0a78bf0d781
diff --git a/libs/partners/anthropic/tests/unit_tests/test_chat_models.py b/libs/partners/anthropic/tests/unit_tests/test_chat_models.py
index 0dbdceb483..9d9518f0ba 100644
--- a/libs/partners/anthropic/tests/unit_tests/test_chat_models.py
+++ b/libs/partners/anthropic/tests/unit_tests/test_chat_models.py
@@ -42,19 +42,22 @@ MODEL_NAME = "claude-sonnet-4-5-20250929"
def test_initialization() -> None:
"""Test chat model initialization."""
- for model in [
- ChatAnthropic(model_name=MODEL_NAME, api_key="xyz", timeout=2), # type: ignore[arg-type, call-arg]
- ChatAnthropic( # type: ignore[call-arg, call-arg, call-arg]
- model=MODEL_NAME,
- anthropic_api_key="xyz",
- default_request_timeout=2,
- base_url="https://api.anthropic.com",
- ),
- ]:
- assert model.model == MODEL_NAME
- assert cast("SecretStr", model.anthropic_api_key).get_secret_value() == "xyz"
- assert model.default_request_timeout == 2.0
- assert model.anthropic_api_url == "https://api.anthropic.com"
+ with patch.dict(os.environ, {"ANTHROPIC_API_URL": "https://api.anthropic.com"}):
+ for model in [
+ ChatAnthropic(model_name=MODEL_NAME, api_key="xyz", timeout=2), # type: ignore[arg-type, call-arg]
+ ChatAnthropic( # type: ignore[call-arg, call-arg, call-arg]
+ model=MODEL_NAME,
+ anthropic_api_key="xyz",
+ default_request_timeout=2,
+ base_url="https://api.anthropic.com",
+ ),
+ ]:
+ assert model.model == MODEL_NAME
+ assert (
+ cast("SecretStr", model.anthropic_api_key).get_secret_value() == "xyz"
+ )
+ assert model.default_request_timeout == 2.0
+ assert model.anthropic_api_url == "https://api.anthropic.com"
def test_user_agent_header_in_client_params() -> None:
diff --git a/libs/partners/anthropic/tests/unit_tests/test_standard.py b/libs/partners/anthropic/tests/unit_tests/test_standard.py
index 75b393dfbd..77bc50e76c 100644
--- a/libs/partners/anthropic/tests/unit_tests/test_standard.py
+++ b/libs/partners/anthropic/tests/unit_tests/test_standard.py
@@ -19,12 +19,15 @@ class TestAnthropicStandard(ChatModelUnitTests):
@property
def chat_model_params(self) -> dict:
- return {"model": _MODEL}
+ return {"model": _MODEL, "base_url": "https://api.anthropic.com"}
@property
def init_from_env_params(self) -> tuple[dict, dict, dict]:
return (
- {"ANTHROPIC_API_KEY": "test"},
+ {
+ "ANTHROPIC_API_KEY": "test",
+ "ANTHROPIC_API_URL": "https://api.anthropic.com",
+ },
{"model": _MODEL},
{"anthropic_api_key": "test"},
)