Skip to content

Commit 20c5343

Browse files
committed
tests
1 parent 39c124d commit 20c5343

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

tests/integrations/openai_agents/test_openai_agents.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ def mock_agent():
117117
frequency_penalty=0.0,
118118
)
119119
agent.tools = []
120+
agent.handoffs = []
121+
agent.output_type = str
120122
return agent
121123

122124

@@ -133,11 +135,14 @@ async def test_agent_invocation_span(
133135
integrations=[OpenAIAgentsIntegration()],
134136
traces_sample_rate=1.0,
135137
)
138+
136139
events = capture_events()
137140

138141
with sentry_sdk.start_transaction(name="test_transaction"):
139-
with patch("agents.Runner.run", new_callable=AsyncMock) as mock_run:
140-
mock_run.return_value = mock_run_result
142+
with patch(
143+
"sentry_sdk.integrations.openai_agents.patches.runner._create_run_wrapper"
144+
) as mock_run:
145+
mock_run.return_value = AsyncMock(return_value=mock_run_result)
141146

142147
await agents.Runner.run(mock_agent, "Test input")
143148

@@ -156,7 +161,7 @@ async def test_agent_invocation_span(
156161

157162
@pytest.mark.asyncio
158163
async def test_tool_execution_span(
159-
sentry_init, capture_events, mock_agent, mock_run_result
164+
sentry_init, capture_events, mock_agent, mock_run_result, mock_tool_call
160165
):
161166
sentry_init(
162167
integrations=[OpenAIAgentsIntegration()],
@@ -166,8 +171,13 @@ async def test_tool_execution_span(
166171
events = capture_events()
167172

168173
with sentry_sdk.start_transaction(name="test_transaction"):
169-
with patch("agents.Runner.run", new_callable=AsyncMock) as mock_run:
170-
mock_run.return_value = mock_run_result
174+
with patch(
175+
"sentry_sdk.integrations.openai_agents.patches.runner._create_run_wrapper"
176+
) as mock_run, patch(
177+
"sentry_sdk.integrations.openai_agents.patches.tools._create_get_all_tools_wrapper"
178+
) as mock_tools:
179+
mock_run.return_value = AsyncMock(return_value=mock_run_result)
180+
mock_tools.return_value = AsyncMock(return_value=[mock_tool_call])
171181

172182
await agents.Runner.run(mock_agent, "Test input")
173183

@@ -194,8 +204,13 @@ async def test_llm_request_span(
194204
events = capture_events()
195205

196206
with sentry_sdk.start_transaction(name="test_transaction"):
197-
with patch("agents.Runner.run", new_callable=AsyncMock) as mock_run:
198-
mock_run.return_value = mock_run_result
207+
with patch(
208+
"sentry_sdk.integrations.openai_agents.patches.runner._create_run_wrapper"
209+
) as mock_run, patch(
210+
"sentry_sdk.integrations.openai_agents.patches.models._create_get_model_wrapper"
211+
) as mock_model:
212+
mock_run.return_value = AsyncMock(return_value=mock_run_result)
213+
mock_model.return_value = AsyncMock(return_value=mock_model_response)
199214

200215
await agents.Runner.run(mock_agent, "Test input")
201216

@@ -221,8 +236,10 @@ async def test_error_handling(sentry_init, capture_events, mock_agent):
221236
events = capture_events()
222237

223238
with sentry_sdk.start_transaction(name="test_transaction") as transaction:
224-
with patch("agents.Runner.run", new_callable=AsyncMock) as mock_run:
225-
mock_run.side_effect = AgentsException("Test error")
239+
with patch(
240+
"sentry_sdk.integrations.openai_agents.patches.runner._create_run_wrapper"
241+
) as mock_run:
242+
mock_run.return_value = AsyncMock(side_effect=AgentsException("Test error"))
226243

227244
with pytest.raises(AgentsException):
228245
await agents.Runner.run(mock_agent, "Test input")

0 commit comments

Comments
 (0)