Skip to content

Commit 2a34bd4

Browse files
.
1 parent 020f1de commit 2a34bd4

1 file changed

Lines changed: 56 additions & 51 deletions

File tree

tests/integrations/openai_agents/test_openai_agents.py

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -201,25 +201,6 @@ def test_agent_custom_model():
201201
)
202202

203203

204-
@pytest.fixture
205-
def get_model_response():
206-
def inner(response_content):
207-
model_request = httpx.Request(
208-
"POST",
209-
"/responses",
210-
)
211-
212-
response = httpx.Response(
213-
200,
214-
request=model_request,
215-
content=json.dumps(response_content.model_dump()).encode("utf-8"),
216-
)
217-
218-
return response
219-
220-
return inner
221-
222-
223204
@pytest.mark.asyncio
224205
async def test_agent_invocation_span_no_pii(
225206
sentry_init, capture_events, test_agent, mock_model_response, get_model_response
@@ -228,7 +209,7 @@ async def test_agent_invocation_span_no_pii(
228209
model = OpenAIResponsesModel(model="gpt-4", openai_client=client)
229210
agent = test_agent.clone(model=model)
230211

231-
response = get_model_response(mock_model_response)
212+
response = get_model_response(mock_model_response, serialize_pydantic=True)
232213

233214
with patch.object(
234215
agent.model._client._client,
@@ -377,7 +358,7 @@ async def test_agent_invocation_span(
377358
model = OpenAIResponsesModel(model="gpt-4", openai_client=client)
378359
agent = test_agent_with_instructions(instructions).clone(model=model)
379360

380-
response = get_model_response(mock_model_response)
361+
response = get_model_response(mock_model_response, serialize_pydantic=True)
381362

382363
with patch.object(
383364
agent.model._client._client,
@@ -538,7 +519,7 @@ async def test_client_span_custom_model(
538519
model = OpenAIResponsesModel(model="my-custom-model", openai_client=client)
539520
agent = test_agent_custom_model.clone(model=model)
540521

541-
response = get_model_response(mock_model_response)
522+
response = get_model_response(mock_model_response, serialize_pydantic=True)
542523

543524
with patch.object(
544525
agent.model._client._client,
@@ -581,7 +562,7 @@ def test_agent_invocation_span_sync_no_pii(
581562
model = OpenAIResponsesModel(model="gpt-4", openai_client=client)
582563
agent = test_agent.clone(model=model)
583564

584-
response = get_model_response(mock_model_response)
565+
response = get_model_response(mock_model_response, serialize_pydantic=True)
585566

586567
with patch.object(
587568
agent.model._client._client,
@@ -724,7 +705,7 @@ def test_agent_invocation_span_sync(
724705
model = OpenAIResponsesModel(model="gpt-4", openai_client=client)
725706
agent = test_agent_with_instructions(instructions).clone(model=model)
726707

727-
response = get_model_response(mock_model_response)
708+
response = get_model_response(mock_model_response, serialize_pydantic=True)
728709

729710
with patch.object(
730711
agent.model._client._client,
@@ -906,7 +887,8 @@ async def test_handoff_span(sentry_init, capture_events, get_model_response):
906887
),
907888
total_tokens=30,
908889
),
909-
)
890+
),
891+
serialize_pydantic=True,
910892
)
911893

912894
final_response = get_model_response(
@@ -944,7 +926,8 @@ async def test_handoff_span(sentry_init, capture_events, get_model_response):
944926
),
945927
total_tokens=30,
946928
),
947-
)
929+
),
930+
serialize_pydantic=True,
948931
)
949932

950933
with patch.object(
@@ -1032,7 +1015,8 @@ async def test_max_turns_before_handoff_span(
10321015
),
10331016
total_tokens=30,
10341017
),
1035-
)
1018+
),
1019+
serialize_pydantic=True,
10361020
)
10371021

10381022
final_response = get_model_response(
@@ -1070,7 +1054,8 @@ async def test_max_turns_before_handoff_span(
10701054
),
10711055
total_tokens=30,
10721056
),
1073-
)
1057+
),
1058+
serialize_pydantic=True,
10741059
)
10751060

10761061
with patch.object(
@@ -1152,7 +1137,8 @@ def simple_test_tool(message: str) -> str:
11521137
),
11531138
total_tokens=15,
11541139
),
1155-
)
1140+
),
1141+
serialize_pydantic=True,
11561142
)
11571143

11581144
final_response = get_model_response(
@@ -1190,7 +1176,8 @@ def simple_test_tool(message: str) -> str:
11901176
),
11911177
total_tokens=25,
11921178
),
1193-
)
1179+
),
1180+
serialize_pydantic=True,
11941181
)
11951182

11961183
with patch.object(
@@ -1898,7 +1885,8 @@ async def test_mcp_tool_execution_spans(
18981885
),
18991886
total_tokens=15,
19001887
),
1901-
)
1888+
),
1889+
serialize_pydantic=True,
19021890
)
19031891

19041892
final_response = get_model_response(
@@ -1936,7 +1924,8 @@ async def test_mcp_tool_execution_spans(
19361924
),
19371925
total_tokens=25,
19381926
),
1939-
)
1927+
),
1928+
serialize_pydantic=True,
19401929
)
19411930

19421931
with patch.object(
@@ -2028,7 +2017,8 @@ async def test_mcp_tool_execution_with_error(
20282017
),
20292018
total_tokens=15,
20302019
),
2031-
)
2020+
),
2021+
serialize_pydantic=True,
20322022
)
20332023

20342024
final_response = get_model_response(
@@ -2066,7 +2056,8 @@ async def test_mcp_tool_execution_with_error(
20662056
),
20672057
total_tokens=25,
20682058
),
2069-
)
2059+
),
2060+
serialize_pydantic=True,
20702061
)
20712062

20722063
with patch.object(
@@ -2156,7 +2147,8 @@ async def test_mcp_tool_execution_without_pii(
21562147
),
21572148
total_tokens=15,
21582149
),
2159-
)
2150+
),
2151+
serialize_pydantic=True,
21602152
)
21612153

21622154
final_response = get_model_response(
@@ -2194,7 +2186,8 @@ async def test_mcp_tool_execution_without_pii(
21942186
),
21952187
total_tokens=25,
21962188
),
2197-
)
2189+
),
2190+
serialize_pydantic=True,
21982191
)
21992192

22002193
with patch.object(
@@ -2252,7 +2245,7 @@ async def test_multiple_agents_asyncio(
22522245
model = OpenAIResponsesModel(model="gpt-4", openai_client=client)
22532246
agent = test_agent.clone(model=model)
22542247

2255-
response = get_model_response(mock_model_response)
2248+
response = get_model_response(mock_model_response, serialize_pydantic=True)
22562249

22572250
with patch.object(
22582251
agent.model._client._client,
@@ -2382,7 +2375,8 @@ def failing_tool(message: str) -> str:
23822375
),
23832376
total_tokens=15,
23842377
),
2385-
)
2378+
),
2379+
serialize_pydantic=True,
23862380
)
23872381

23882382
final_response = get_model_response(
@@ -2420,7 +2414,8 @@ def failing_tool(message: str) -> str:
24202414
),
24212415
total_tokens=25,
24222416
),
2423-
)
2417+
),
2418+
serialize_pydantic=True,
24242419
)
24252420

24262421
with patch.object(
@@ -2515,7 +2510,8 @@ async def test_invoke_agent_span_includes_usage_data(
25152510
),
25162511
total_tokens=30,
25172512
),
2518-
)
2513+
),
2514+
serialize_pydantic=True,
25192515
)
25202516

25212517
with patch.object(
@@ -2606,7 +2602,8 @@ async def test_ai_client_span_includes_response_model(
26062602
),
26072603
total_tokens=30,
26082604
),
2609-
)
2605+
),
2606+
serialize_pydantic=True,
26102607
)
26112608

26122609
with patch.object(
@@ -2693,7 +2690,8 @@ async def test_ai_client_span_response_model_with_chat_completions(
26932690
),
26942691
total_tokens=40,
26952692
),
2696-
)
2693+
),
2694+
serialize_pydantic=True,
26972695
)
26982696

26992697
with patch.object(
@@ -2770,7 +2768,8 @@ def calculator(a: int, b: int) -> int:
27702768
),
27712769
total_tokens=15,
27722770
),
2773-
)
2771+
),
2772+
serialize_pydantic=True,
27742773
)
27752774

27762775
final_response = get_model_response(
@@ -2808,7 +2807,8 @@ def calculator(a: int, b: int) -> int:
28082807
),
28092808
total_tokens=35,
28102809
),
2811-
)
2810+
),
2811+
serialize_pydantic=True,
28122812
)
28132813

28142814
with patch.object(
@@ -2896,7 +2896,8 @@ async def test_invoke_agent_span_includes_response_model(
28962896
),
28972897
total_tokens=30,
28982898
),
2899-
)
2899+
),
2900+
serialize_pydantic=True,
29002901
)
29012902

29022903
with patch.object(
@@ -2985,7 +2986,8 @@ def calculator(a: int, b: int) -> int:
29852986
),
29862987
total_tokens=15,
29872988
),
2988-
)
2989+
),
2990+
serialize_pydantic=True,
29892991
)
29902992

29912993
second_response = get_model_response(
@@ -3023,7 +3025,8 @@ def calculator(a: int, b: int) -> int:
30233025
),
30243026
total_tokens=35,
30253027
),
3026-
)
3028+
),
3029+
serialize_pydantic=True,
30273030
)
30283031

30293032
with patch.object(
@@ -3325,7 +3328,7 @@ async def test_conversation_id_on_all_spans(
33253328
model = OpenAIResponsesModel(model="gpt-4", openai_client=client)
33263329
agent = test_agent.clone(model=model)
33273330

3328-
response = get_model_response(mock_model_response)
3331+
response = get_model_response(mock_model_response, serialize_pydantic=True)
33293332

33303333
with patch.object(
33313334
agent.model._client._client,
@@ -3418,7 +3421,8 @@ def simple_tool(message: str) -> str:
34183421
),
34193422
total_tokens=15,
34203423
),
3421-
)
3424+
),
3425+
serialize_pydantic=True,
34223426
)
34233427

34243428
final_response = get_model_response(
@@ -3456,7 +3460,8 @@ def simple_tool(message: str) -> str:
34563460
),
34573461
total_tokens=30,
34583462
),
3459-
)
3463+
),
3464+
serialize_pydantic=True,
34603465
)
34613466

34623467
with patch.object(
@@ -3519,7 +3524,7 @@ async def test_no_conversation_id_when_not_provided(
35193524
model = OpenAIResponsesModel(model="gpt-4", openai_client=client)
35203525
agent = test_agent.clone(model=model)
35213526

3522-
response = get_model_response(mock_model_response)
3527+
response = get_model_response(mock_model_response, serialize_pydantic=True)
35233528

35243529
with patch.object(
35253530
agent.model._client._client,

0 commit comments

Comments
 (0)