Skip to content

Commit 6b509e3

Browse files
committed
empty assertions
1 parent a00b61f commit 6b509e3

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

Diff for: tests/test_agent_tracing.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from .fake_model import FakeModel
1111
from .test_responses import get_text_message
12-
from .testing_processor import fetch_normalized_spans, fetch_traces
12+
from .testing_processor import assert_no_traces, fetch_normalized_spans, fetch_traces
1313

1414

1515
@pytest.mark.asyncio
@@ -164,7 +164,7 @@ async def test_parent_disabled_trace_disabled_agent_trace():
164164

165165
await Runner.run(agent, input="first_test")
166166

167-
assert fetch_normalized_spans() == snapshot([])
167+
assert_no_traces()
168168

169169

170170
@pytest.mark.asyncio
@@ -178,7 +178,7 @@ async def test_manual_disabling_works():
178178

179179
await Runner.run(agent, input="first_test", run_config=RunConfig(tracing_disabled=True))
180180

181-
assert fetch_normalized_spans() == snapshot([])
181+
assert_no_traces()
182182

183183

184184
@pytest.mark.asyncio
@@ -370,8 +370,7 @@ async def test_parent_disabled_trace_disables_streaming_agent_trace():
370370
async for _ in x.stream_events():
371371
pass
372372

373-
traces = fetch_traces()
374-
assert len(traces) == 0, f"Expected 0 traces, got {len(traces)}"
373+
assert_no_traces()
375374

376375

377376
@pytest.mark.asyncio
@@ -392,5 +391,4 @@ async def test_manual_streaming_disabling_works():
392391
async for _ in x.stream_events():
393392
pass
394393

395-
traces = fetch_traces()
396-
assert len(traces) == 0, f"Expected 0 traces, got {len(traces)}"
394+
assert_no_traces()

Diff for: tests/test_responses_tracing.py

+8-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from agents.tracing.span_data import ResponseSpanData
88
from tests import fake_model
99

10-
from .testing_processor import fetch_normalized_spans, fetch_ordered_spans
10+
from .testing_processor import fetch_normalized_spans, fetch_ordered_spans, assert_no_spans
1111

1212

1313
class DummyTracing:
@@ -89,9 +89,8 @@ async def dummy_fetch_response(
8989
[{"workflow_name": "test", "children": [{"type": "response"}]}]
9090
)
9191

92-
spans = fetch_ordered_spans()
93-
assert len(spans) == 1
94-
assert spans[0].span_data.response is None
92+
[span] = fetch_ordered_spans()
93+
assert span.span_data.response is None
9594

9695

9796
@pytest.mark.allow_call_model_methods
@@ -116,9 +115,7 @@ async def dummy_fetch_response(
116115

117116
assert fetch_normalized_spans() == snapshot([{"workflow_name": "test"}])
118117

119-
spans = fetch_ordered_spans()
120-
assert len(spans) == 0
121-
118+
assert_no_spans()
122119

123120
@pytest.mark.allow_call_model_methods
124121
@pytest.mark.asyncio
@@ -190,10 +187,9 @@ async def __aiter__(self):
190187
[{"workflow_name": "test", "children": [{"type": "response"}]}]
191188
)
192189

193-
spans = fetch_ordered_spans()
194-
assert len(spans) == 1
195-
assert isinstance(spans[0].span_data, ResponseSpanData)
196-
assert spans[0].span_data.response is None
190+
[span] = fetch_ordered_spans()
191+
assert isinstance(span.span_data, ResponseSpanData)
192+
assert span.span_data.response is None
197193

198194

199195
@pytest.mark.allow_call_model_methods
@@ -226,5 +222,4 @@ async def __aiter__(self):
226222

227223
assert fetch_normalized_spans() == snapshot([{"workflow_name": "test"}])
228224

229-
spans = fetch_ordered_spans()
230-
assert len(spans) == 0
225+
assert_no_spans()

Diff for: tests/test_tracing.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
fetch_normalized_spans,
2525
fetch_ordered_spans,
2626
fetch_traces,
27+
assert_no_traces,
2728
)
2829

2930
### HELPERS
@@ -281,10 +282,7 @@ def disabled_tracing():
281282

282283
def test_disabled_tracing():
283284
disabled_tracing()
284-
285-
spans, traces = fetch_ordered_spans(), fetch_traces()
286-
assert len(spans) == 0
287-
assert len(traces) == 0
285+
assert_no_traces()
288286

289287

290288
def enabled_trace_disabled_span():
@@ -374,9 +372,7 @@ async def test_noop_span_doesnt_record():
374372
with custom_span(name="span_1") as span:
375373
span.set_error(SpanError(message="test", data={}))
376374

377-
spans, traces = fetch_ordered_spans(), fetch_traces()
378-
assert len(spans) == 0
379-
assert len(traces) == 0
375+
assert_no_traces()
380376

381377
assert t.export() is None
382378
assert span.export() is None

Diff for: tests/testing_processor.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ def fetch_events() -> list[TestSpanProcessorEvent]:
8080
return SPAN_PROCESSOR_TESTING._events
8181

8282

83+
def assert_no_spans():
84+
spans = fetch_ordered_spans()
85+
if spans:
86+
raise AssertionError(f"Expected 0 spans, got {len(spans)}")
87+
88+
89+
def assert_no_traces():
90+
traces = fetch_traces()
91+
if traces:
92+
raise AssertionError(f"Expected 0 traces, got {len(traces)}")
93+
assert_no_spans()
94+
95+
8396
def fetch_normalized_spans(keep_span_id: bool = False):
8497
nodes: dict[tuple[str, str | None], dict[str, Any]] = {}
8598
traces = []
@@ -92,8 +105,7 @@ def fetch_normalized_spans(keep_span_id: bool = False):
92105
nodes[(trace_obj.trace_id, None)] = trace
93106
traces.append(trace)
94107

95-
if not traces:
96-
assert not fetch_ordered_spans()
108+
assert traces, "Use assert_no_traces() to check for empty traces"
97109

98110
for span_obj in fetch_ordered_spans():
99111
span = span_obj.export()

0 commit comments

Comments
 (0)