fix: clear litellm.api_key in OpenRouter validate_environment test

The test_validate_environment_raises_without_key test was failing because
litellm.api_key may be set globally in the test environment. Clear it
along with OPENROUTER_API_KEY and OR_API_KEY env vars using monkeypatch.

Co-authored-by: Ishaan Jaff <ishaan-jaff@users.noreply.github.com>
This commit is contained in:
Cursor Agent 2026-03-07 03:16:57 +00:00
parent 1f3d9f0428
commit fb238777c1

View file

@ -60,11 +60,16 @@ class TestOpenRouterResponsesAPIConfig:
)
assert headers["Authorization"] == "Bearer sk-or-test-key"
def test_validate_environment_raises_without_key(self):
def test_validate_environment_raises_without_key(self, monkeypatch):
"""validate_environment should raise when no API key is available."""
config = OpenRouterResponsesAPIConfig()
from litellm.types.router import GenericLiteLLMParams
# Clear any globally set API keys so the validation correctly raises
monkeypatch.setattr(litellm, "api_key", None)
monkeypatch.delenv("OPENROUTER_API_KEY", raising=False)
monkeypatch.delenv("OR_API_KEY", raising=False)
try:
config.validate_environment(
headers={},