Skip to content

Commit bfbfc65

Browse files
John-Linclaude
andcommitted
Mock OpenAI model in tests to prevent real API client construction
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 70d2450 commit bfbfc65

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

tests/test_agents.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
from __future__ import annotations
22

3+
from unittest.mock import create_autospec
4+
5+
import pytest
6+
from agents.models.interface import Model
7+
38
from bot.agents import DEFAULT_INSTRUCTIONS
49
from bot.agents import MAX_TURNS
510
from bot.agents import OpenAIAgent
611

712

13+
@pytest.fixture(autouse=True)
14+
def _mock_model(monkeypatch):
15+
"""Prevent tests from constructing a real OpenAI client."""
16+
monkeypatch.setattr("bot.agents._get_model", lambda: create_autospec(Model))
17+
18+
819
class TestPerChatConversations:
920
def test_separate_chats_have_independent_history(self):
1021
"""Different chat_ids should maintain separate message histories."""

0 commit comments

Comments
 (0)