Skip to content

Commit 68ba0b0

Browse files
committed
🐛 fix: add autouse fixture for API keys in unit tests
Add mock_openai_key fixture with autouse=True to automatically set fake API keys for all unit tests, preventing OpenAI API key errors when running tests in CI or local environments without credentials. This fixes the CI failure where 7 tests were failing with: "The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable"
1 parent 5117a52 commit 68ba0b0

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

apps/sample-deep-agent/tests/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
"""Test configuration and fixtures."""
22

3+
import os
34
from unittest.mock import Mock, patch
45

56
import pytest
67

78

9+
@pytest.fixture(autouse=True)
10+
def mock_openai_key(monkeypatch):
11+
"""Mock OPENAI_API_KEY to prevent API key errors in unit tests."""
12+
monkeypatch.setenv("OPENAI_API_KEY", "sk-test-fake-key-for-unit-tests")
13+
monkeypatch.setenv("OPENROUTER_API_KEY", "sk-test-fake-key-for-unit-tests")
14+
15+
816
@pytest.fixture
917
def mock_model():
1018
"""Mock chat model for testing."""

apps/sample-deep-agent/tests/unit/test_graph.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Unit tests for sample deep agent graph components."""
22

3+
import pytest
34
from unittest.mock import Mock, patch
45

56
from sample_deep_agent.context import DeepAgentContext

0 commit comments

Comments
 (0)