mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-04-12 22:12:37 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user