1818 Runner ,
1919 TResponseInputItem ,
2020)
21- from agents .tracing import AgentSpanData , FunctionSpanData , GenerationSpanData
2221
2322from .fake_model import FakeModel
2423from .test_responses import (
2827 get_handoff_tool_call ,
2928 get_text_message ,
3029)
31- from .testing_processor import fetch_normalized_spans , fetch_ordered_spans , fetch_traces
30+ from .testing_processor import fetch_normalized_spans
3231
3332
3433@pytest .mark .asyncio
@@ -43,9 +42,6 @@ async def test_single_turn_model_error():
4342 with pytest .raises (ValueError ):
4443 await Runner .run (agent , input = "first_test" )
4544
46- traces = fetch_traces ()
47- assert len (traces ) == 1 , f"Expected 1 trace, got { len (traces )} "
48-
4945 assert fetch_normalized_spans () == snapshot (
5046 [
5147 {
@@ -74,13 +70,6 @@ async def test_single_turn_model_error():
7470 ]
7571 )
7672
77- spans = fetch_ordered_spans ()
78- assert len (spans ) == 2 , f"should have agent and generation spans, got { len (spans )} "
79-
80- generation_span = spans [1 ]
81- assert isinstance (generation_span .span_data , GenerationSpanData )
82- assert generation_span .error , "should have error"
83-
8473
8574@pytest .mark .asyncio
8675async def test_multi_turn_no_handoffs ():
@@ -106,9 +95,6 @@ async def test_multi_turn_no_handoffs():
10695 with pytest .raises (ValueError ):
10796 await Runner .run (agent , input = "first_test" )
10897
109- traces = fetch_traces ()
110- assert len (traces ) == 1 , f"Expected 1 trace, got { len (traces )} "
111-
11298 assert fetch_normalized_spans () == snapshot (
11399 [
114100 {
@@ -146,15 +132,6 @@ async def test_multi_turn_no_handoffs():
146132 ]
147133 )
148134
149- spans = fetch_ordered_spans ()
150- assert len (spans ) == 4 , (
151- f"should have agent, generation, tool, generation, got { len (spans )} with data: "
152- f"{ [x .span_data for x in spans ]} "
153- )
154-
155- last_generation_span = [x for x in spans if isinstance (x .span_data , GenerationSpanData )][- 1 ]
156- assert last_generation_span .error , "should have error"
157-
158135
159136@pytest .mark .asyncio
160137async def test_tool_call_error ():
@@ -173,9 +150,6 @@ async def test_tool_call_error():
173150 with pytest .raises (ModelBehaviorError ):
174151 await Runner .run (agent , input = "first_test" )
175152
176- traces = fetch_traces ()
177- assert len (traces ) == 1 , f"Expected 1 trace, got { len (traces )} "
178-
179153 assert fetch_normalized_spans () == snapshot (
180154 [
181155 {
@@ -209,15 +183,6 @@ async def test_tool_call_error():
209183 ]
210184 )
211185
212- spans = fetch_ordered_spans ()
213- assert len (spans ) == 3 , (
214- f"should have agent, generation, tool spans, got { len (spans )} with data: "
215- f"{ [x .span_data for x in spans ]} "
216- )
217-
218- function_span = [x for x in spans if isinstance (x .span_data , FunctionSpanData )][0 ]
219- assert function_span .error , "should have error"
220-
221186
222187@pytest .mark .asyncio
223188async def test_multiple_handoff_doesnt_error ():
@@ -255,9 +220,6 @@ async def test_multiple_handoff_doesnt_error():
255220 result = await Runner .run (agent_3 , input = "user_message" )
256221 assert result .last_agent == agent_1 , "should have picked first handoff"
257222
258- traces = fetch_traces ()
259- assert len (traces ) == 1 , f"Expected 1 trace, got { len (traces )} "
260-
261223 assert fetch_normalized_spans () == snapshot (
262224 [
263225 {
@@ -295,12 +257,6 @@ async def test_multiple_handoff_doesnt_error():
295257 ]
296258 )
297259
298- spans = fetch_ordered_spans ()
299- assert len (spans ) == 7 , (
300- f"should have 2 agent, 1 function, 3 generation, 1 handoff, got { len (spans )} with data: "
301- f"{ [x .span_data for x in spans ]} "
302- )
303-
304260
305261class Foo (TypedDict ):
306262 bar : str
@@ -326,9 +282,6 @@ async def test_multiple_final_output_doesnt_error():
326282 result = await Runner .run (agent_1 , input = "user_message" )
327283 assert result .final_output == Foo (bar = "abc" )
328284
329- traces = fetch_traces ()
330- assert len (traces ) == 1 , f"Expected 1 trace, got { len (traces )} "
331-
332285 assert fetch_normalized_spans () == snapshot (
333286 [
334287 {
@@ -344,12 +297,6 @@ async def test_multiple_final_output_doesnt_error():
344297 ]
345298 )
346299
347- spans = fetch_ordered_spans ()
348- assert len (spans ) == 2 , (
349- f"should have 1 agent, 1 generation, got { len (spans )} with data: "
350- f"{ [x .span_data for x in spans ]} "
351- )
352-
353300
354301@pytest .mark .asyncio
355302async def test_handoffs_lead_to_correct_agent_spans ():
@@ -399,9 +346,6 @@ async def test_handoffs_lead_to_correct_agent_spans():
399346 f"should have ended on the third agent, got { result .last_agent .name } "
400347 )
401348
402- traces = fetch_traces ()
403- assert len (traces ) == 1 , f"Expected 1 trace, got { len (traces )} "
404-
405349 assert fetch_normalized_spans () == snapshot (
406350 [
407351 {
@@ -472,12 +416,6 @@ async def test_handoffs_lead_to_correct_agent_spans():
472416 ]
473417 )
474418
475- spans = fetch_ordered_spans ()
476- assert len (spans ) == 12 , (
477- f"should have 3 agents, 2 function, 5 generation, 2 handoff, got { len (spans )} with data: "
478- f"{ [x .span_data for x in spans ]} "
479- )
480-
481419
482420@pytest .mark .asyncio
483421async def test_max_turns_exceeded ():
@@ -503,9 +441,6 @@ async def test_max_turns_exceeded():
503441 with pytest .raises (MaxTurnsExceeded ):
504442 await Runner .run (agent , input = "user_message" , max_turns = 2 )
505443
506- traces = fetch_traces ()
507- assert len (traces ) == 1 , f"Expected 1 trace, got { len (traces )} "
508-
509444 assert fetch_normalized_spans () == snapshot (
510445 [
511446 {
@@ -538,15 +473,6 @@ async def test_max_turns_exceeded():
538473 ]
539474 )
540475
541- spans = fetch_ordered_spans ()
542- assert len (spans ) == 5 , (
543- f"should have 1 agent span, 2 generations, 2 function calls, got "
544- f"{ len (spans )} with data: { [x .span_data for x in spans ]} "
545- )
546-
547- agent_span = [x for x in spans if isinstance (x .span_data , AgentSpanData )][- 1 ]
548- assert agent_span .error , "last agent should have error"
549-
550476
551477def guardrail_function (
552478 context : RunContextWrapper [Any ], agent : Agent [Any ], input : str | list [TResponseInputItem ]
@@ -568,9 +494,6 @@ async def test_guardrail_error():
568494 with pytest .raises (InputGuardrailTripwireTriggered ):
569495 await Runner .run (agent , input = "user_message" )
570496
571- traces = fetch_traces ()
572- assert len (traces ) == 1 , f"Expected 1 trace, got { len (traces )} "
573-
574497 assert fetch_normalized_spans () == snapshot (
575498 [
576499 {
@@ -594,12 +517,3 @@ async def test_guardrail_error():
594517 }
595518 ]
596519 )
597-
598- spans = fetch_ordered_spans ()
599- assert len (spans ) == 2 , (
600- f"should have 1 agent, 1 guardrail, got { len (spans )} with data: "
601- f"{ [x .span_data for x in spans ]} "
602- )
603-
604- agent_span = [x for x in spans if isinstance (x .span_data , AgentSpanData )][- 1 ]
605- assert agent_span .error , "last agent should have error"
0 commit comments