Skip to content

Commit 22caaca

Browse files
clean up list comprehensions in tests
1 parent 06d049e commit 22caaca

1 file changed

Lines changed: 14 additions & 18 deletions

File tree

tests/integrations/pydantic_ai/test_pydantic_ai.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ async def test_agent_run_async(
9090
assert result.output is not None
9191

9292
sentry_sdk.flush()
93-
spans = [item.payload for item in items if item.type == "span"]
93+
spans = [item.payload for item in items]
9494

9595
assert spans[1]["name"] == "invoke_agent test_agent"
9696
assert spans[1]["attributes"]["sentry.origin"] == "auto.ai.pydantic_ai"
@@ -235,7 +235,7 @@ def failing_model(messages, info):
235235
)
236236

237237
if span_streaming:
238-
items = capture_items("event", "transaction", "span")
238+
items = capture_items("event", "span")
239239

240240
with pytest.raises(RuntimeError, match="model exploded"):
241241
await agent.run("Test input")
@@ -310,11 +310,7 @@ def test_agent_run_sync(
310310
assert result.output is not None
311311

312312
sentry_sdk.flush()
313-
spans = [item.payload for item in items if item.type == "span"]
314-
315-
# Find span types
316-
sentry_sdk.flush()
317-
spans = [item.payload for item in items if item.type == "span"]
313+
spans = [item.payload for item in items]
318314

319315
assert spans[1]["name"] == "invoke_agent test_agent"
320316
assert spans[1]["attributes"]["sentry.origin"] == "auto.ai.pydantic_ai"
@@ -403,7 +399,7 @@ def failing_model(messages, info):
403399
)
404400

405401
if span_streaming:
406-
items = capture_items("event", "transaction", "span")
402+
items = capture_items("event", "span")
407403

408404
with pytest.raises(RuntimeError, match="model exploded"):
409405
agent.run_sync("Test input")
@@ -479,7 +475,7 @@ async def test_agent_run_stream(
479475
pass
480476

481477
sentry_sdk.flush()
482-
spans = [item.payload for item in items if item.type == "span"]
478+
spans = [item.payload for item in items]
483479

484480
assert spans[1]["name"] == "invoke_agent test_agent"
485481
assert spans[1]["attributes"]["sentry.origin"] == "auto.ai.pydantic_ai"
@@ -637,7 +633,7 @@ async def test_agent_run_stream_events(
637633
pass
638634

639635
sentry_sdk.flush()
640-
spans = [item.payload for item in items if item.type == "span"]
636+
spans = [item.payload for item in items]
641637

642638
assert spans[-1]["name"] == "invoke_agent test_agent"
643639

@@ -1359,7 +1355,7 @@ async def test_error_handling(
13591355
await agent.run("Hello")
13601356

13611357
sentry_sdk.flush()
1362-
spans = [item.payload for item in items if item.type == "span"]
1358+
spans = [item.payload for item in items]
13631359

13641360
assert spans[1]["is_segment"] is True
13651361
assert spans[1]["status"] != "error" # Could be None or some other status
@@ -1550,7 +1546,7 @@ async def run_agent(input_text):
15501546
assert len(results) == 3
15511547

15521548
sentry_sdk.flush()
1553-
spans = [item.payload for item in items if item.type == "span"]
1549+
spans = [item.payload for item in items]
15541550
for span in spans:
15551551
if span["is_segment"] is False:
15561552
continue
@@ -2157,7 +2153,7 @@ async def test_invoke_agent_with_list_user_prompt(
21572153
await agent.run(["First part", "Second part"])
21582154

21592155
sentry_sdk.flush()
2160-
spans = [item.payload for item in items if item.type == "span"]
2156+
spans = [item.payload for item in items]
21612157

21622158
# Check that the invoke_agent transaction has messages data
21632159
# The invoke_agent is the transaction itself
@@ -2471,7 +2467,7 @@ async def test_agent_data_from_scope(
24712467
await agent.run("Test input")
24722468

24732469
sentry_sdk.flush()
2474-
spans = [item.payload for item in items if item.type == "span"]
2470+
spans = [item.payload for item in items]
24752471

24762472
assert spans[1]["name"] == "invoke_agent test_scope_agent"
24772473
elif stream_gen_ai_spans:
@@ -2791,7 +2787,7 @@ async def test_agent_without_name(
27912787
await agent.run("Test input")
27922788

27932789
sentry_sdk.flush()
2794-
spans = [item.payload for item in items if item.type == "span"]
2790+
spans = [item.payload for item in items]
27952791

27962792
assert "invoke_agent" in spans[1]["name"]
27972793
elif stream_gen_ai_spans:
@@ -3969,7 +3965,7 @@ async def test_binary_content_encoding_image(
39693965
span.finish()
39703966

39713967
sentry_sdk.flush()
3972-
spans = [item.payload for item in items if item.type == "span"]
3968+
spans = [item.payload for item in items]
39733969

39743970
span_data = spans[0]["attributes"]
39753971
messages_data = _get_messages_from_span(span_data)
@@ -4058,7 +4054,7 @@ async def test_binary_content_encoding_mixed_content(
40584054
span.finish()
40594055

40604056
sentry_sdk.flush()
4061-
spans = [item.payload for item in items if item.type == "span"]
4057+
spans = [item.payload for item in items]
40624058

40634059
span_data = spans[0]["attributes"]
40644060
messages_data = _get_messages_from_span(span_data)
@@ -4234,7 +4230,7 @@ async def test_set_usage_data_with_cache_tokens(
42344230
span.finish()
42354231

42364232
sentry_sdk.flush()
4237-
spans = [item.payload for item in items if item.type == "span"]
4233+
spans = [item.payload for item in items]
42384234

42394235
assert spans[0]["attributes"][SPANDATA.GEN_AI_USAGE_INPUT_TOKENS_CACHED] == 80
42404236
assert (

0 commit comments

Comments
 (0)