@@ -424,31 +424,21 @@ def _make_agents_mock(runner_run_mock: Any) -> MagicMock:
424424 mock_runner_cls = MagicMock ()
425425 mock_runner_cls .run = runner_run_mock
426426
427- mock_agent_cls = MagicMock ()
428-
429- mock_function_tool_cls = MagicMock (side_effect = lambda ** kw : MagicMock (** kw ))
430-
431- mock_model_settings_cls = MagicMock (side_effect = lambda ** kw : MagicMock (** kw ))
432-
433427 mock_tool_context_module = MagicMock ()
434428 mock_tool_context_module .ToolContext = MagicMock ()
435429
436430 agents_mock = MagicMock ()
437- agents_mock .Agent = mock_agent_cls
431+ agents_mock .Agent = MagicMock ()
438432 agents_mock .Runner = mock_runner_cls
439- agents_mock .FunctionTool = mock_function_tool_cls
440- agents_mock .ModelSettings = mock_model_settings_cls
433+ agents_mock .FunctionTool = MagicMock ( side_effect = lambda ** kw : MagicMock ( ** kw ))
434+ agents_mock .ModelSettings = MagicMock ( side_effect = lambda ** kw : MagicMock ( ** kw ))
441435
442436 return agents_mock , mock_tool_context_module
443437
444438
445439class TestOpenAIAgentRunner :
446440 """Tests for OpenAIAgentRunner.run."""
447441
448- @pytest .fixture
449- def mock_client (self ):
450- return MagicMock ()
451-
452442 def _make_run_result (self , output : str , total : int = 15 , input_tokens : int = 10 , output_tokens : int = 5 ):
453443 """Build a mock RunResult with final_output and context_wrapper.usage."""
454444 mock_usage = MagicMock ()
@@ -465,7 +455,7 @@ def _make_run_result(self, output: str, total: int = 15, input_tokens: int = 10,
465455 return mock_result
466456
467457 @pytest .mark .asyncio
468- async def test_runs_agent_and_returns_result_with_no_tool_calls (self , mock_client ):
458+ async def test_runs_agent_and_returns_result_with_no_tool_calls (self ):
469459 """Should return AgentResult when Runner.run returns a final output."""
470460 import sys
471461
@@ -474,7 +464,7 @@ async def test_runs_agent_and_returns_result_with_no_tool_calls(self, mock_clien
474464 mock_run_result = self ._make_run_result ("The answer is 42." , total = 15 , input_tokens = 10 , output_tokens = 5 )
475465 agents_mock , tc_mock = _make_agents_mock (AsyncMock (return_value = mock_run_result ))
476466
477- runner = OpenAIAgentRunner (mock_client , 'gpt-4' , {}, 'You are helpful.' , [], {})
467+ runner = OpenAIAgentRunner ('gpt-4' , {}, 'You are helpful.' , [], {})
478468 with patch .dict (sys .modules , {'agents' : agents_mock , 'agents.tool_context' : tc_mock }):
479469 result = await runner .run ("What is the answer?" )
480470
@@ -484,7 +474,7 @@ async def test_runs_agent_and_returns_result_with_no_tool_calls(self, mock_clien
484474 assert result .metrics .usage .total == 15
485475
486476 @pytest .mark .asyncio
487- async def test_executes_tool_calls_and_returns_final_response (self , mock_client ):
477+ async def test_executes_tool_calls_and_returns_final_response (self ):
488478 """Should delegate tool-calling loop to Runner.run and return final output."""
489479 import sys
490480
@@ -495,7 +485,7 @@ async def test_executes_tool_calls_and_returns_final_response(self, mock_client)
495485
496486 weather_fn = MagicMock (return_value = "Sunny, 25°C" )
497487 runner = OpenAIAgentRunner (
498- mock_client , 'gpt-4' , {}, 'You are helpful.' ,
488+ 'gpt-4' , {}, 'You are helpful.' ,
499489 [{'name' : 'get-weather' , 'description' : 'Get weather' , 'parameters' : {}}],
500490 {'get-weather' : weather_fn },
501491 )
@@ -507,29 +497,29 @@ async def test_executes_tool_calls_and_returns_final_response(self, mock_client)
507497 assert result .metrics .usage .total == 43
508498
509499 @pytest .mark .asyncio
510- async def test_returns_failure_when_exception_thrown (self , mock_client ):
500+ async def test_returns_failure_when_exception_thrown (self ):
511501 """Should return unsuccessful AgentResult when Runner.run raises."""
512502 import sys
513503
514504 from ldai_openai import OpenAIAgentRunner
515505
516506 agents_mock , tc_mock = _make_agents_mock (AsyncMock (side_effect = Exception ("API Error" )))
517507
518- runner = OpenAIAgentRunner (mock_client , 'gpt-4' , {}, '' , [], {})
508+ runner = OpenAIAgentRunner ('gpt-4' , {}, '' , [], {})
519509 with patch .dict (sys .modules , {'agents' : agents_mock , 'agents.tool_context' : tc_mock }):
520510 result = await runner .run ("Hello" )
521511
522512 assert result .output == ""
523513 assert result .metrics .success is False
524514
525515 @pytest .mark .asyncio
526- async def test_returns_failure_when_openai_agents_not_installed (self , mock_client ):
516+ async def test_returns_failure_when_openai_agents_not_installed (self ):
527517 """Should return unsuccessful AgentResult when openai-agents is not installed."""
528518 import sys
529519
530520 from ldai_openai import OpenAIAgentRunner
531521
532- runner = OpenAIAgentRunner (mock_client , 'gpt-4' , {}, '' , [], {})
522+ runner = OpenAIAgentRunner ('gpt-4' , {}, '' , [], {})
533523 with patch .dict (sys .modules , {'agents' : None }):
534524 result = await runner .run ("Hello" )
535525
0 commit comments