Skip to content

Commit c0bf32f

Browse files
Mock OpenAI client in tests to avoid dependency on OPENAI_API_KEY
1 parent 422ce80 commit c0bf32f

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

tests/llm/test_response_api.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,11 @@ def test_openai_chat_completion_api_message_builder_image():
231231

232232
def test_openai_chat_completion_model_parse_and_cost():
233233
args = OpenAIChatModelArgs(model_name="gpt-3.5-turbo") # A cheap model for testing
234-
model = args.make_model()
234+
# Mock the OpenAI client to avoid needing OPENAI_API_KEY
235+
with patch("agentlab.llm.response_api.OpenAI") as mock_openai_class:
236+
mock_client = MagicMock()
237+
mock_openai_class.return_value = mock_client
238+
model = args.make_model()
235239

236240
# Mock the API call
237241
mock_response = create_mock_openai_chat_completion(
@@ -308,8 +312,7 @@ def test_openai_response_model_parse_and_cost():
308312
function_call and reasoning outputs.
309313
"""
310314
args = OpenAIResponseModelArgs(model_name="gpt-4.1")
311-
model = args.make_model()
312-
315+
313316
# Mock outputs
314317
mock_function_call_output = {
315318
"type": "function_call",
@@ -323,6 +326,12 @@ def test_openai_response_model_parse_and_cost():
323326
input_tokens=70,
324327
output_tokens=40,
325328
)
329+
330+
# Mock the OpenAI client to avoid needing OPENAI_API_KEY
331+
with patch('agentlab.llm.response_api.OpenAI') as mock_openai_class:
332+
mock_client = MagicMock()
333+
mock_openai_class.return_value = mock_client
334+
model = args.make_model()
326335

327336
with patch.object(
328337
model.client.responses, "create", return_value=mock_api_resp

0 commit comments

Comments
 (0)