test: update test_create_llm_openai_missing_api_key for lazy init

`LLM(model="gpt-4o")` no longer raises at construction when
`OPENAI_API_KEY` is missing — the descriptive error now surfaces when
the client is actually built. Update the test to assert that contract:
`create_llm` succeeds, and `llm._get_sync_client()` raises.
This commit is contained in:
Greyson LaLonde
2026-04-12 04:42:19 +08:00
parent 6f87078631
commit 77e66647b0

View File

@@ -119,10 +119,12 @@ def test_create_llm_with_invalid_type() -> None:
def test_create_llm_openai_missing_api_key() -> None:
"""Test that create_llm raises error when OpenAI API key is missing"""
"""Credentials are validated lazily: `create_llm` succeeds, and the
descriptive error only surfaces when the client is actually built."""
with patch.dict(os.environ, {}, clear=True):
llm = create_llm(llm_value="gpt-4o")
with pytest.raises((ValueError, ImportError)) as exc_info:
create_llm(llm_value="gpt-4o")
llm._get_sync_client()
error_message = str(exc_info.value).lower()
assert "openai_api_key" in error_message or "api_key" in error_message