From 2d33a9444aa18c89a61a91c6112c110a96949c58 Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Thu, 21 May 2026 16:10:20 +0200 Subject: [PATCH 1/4] test(pydantic-ai): Support Agent.run_stream_events() returning a context manager --- .../pydantic_ai/test_pydantic_ai.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/integrations/pydantic_ai/test_pydantic_ai.py b/tests/integrations/pydantic_ai/test_pydantic_ai.py index 9a1fe79167..20fe927b83 100644 --- a/tests/integrations/pydantic_ai/test_pydantic_ai.py +++ b/tests/integrations/pydantic_ai/test_pydantic_ai.py @@ -17,6 +17,9 @@ from sentry_sdk.integrations.pydantic_ai import PydanticAIIntegration from sentry_sdk.integrations.pydantic_ai.spans.ai_client import _set_input_messages from sentry_sdk.integrations.pydantic_ai.spans.utils import _set_usage_data +from sentry_sdk.utils import package_version + +PYDANTIC_VERSION = package_version("pydantic-ai") @pytest.fixture @@ -517,10 +520,18 @@ async def test_agent_run_stream_events( if stream_gen_ai_spans: items = capture_items("transaction", "span") - async for _ in test_agent.run_stream_events( - ["Message demonstrating the absence of truncation.", "Test input"] - ): - pass + if PYDANTIC_VERSION > (2,): + async with test_agent.run_stream_events( + ["Message demonstrating the absence of truncation.", "Test input"] + ) as events: + async for _ in events: + pass + yield + else: + async for _ in test_agent.run_stream_events( + ["Message demonstrating the absence of truncation.", "Test input"] + ): + pass # Verify transaction (transaction,) = (item.payload for item in items if item.type == "transaction") From 0f62288cc5976aaf0f5d919a5c11726ed6d372bc Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Thu, 21 May 2026 16:12:56 +0200 Subject: [PATCH 2/4] remove yield --- tests/integrations/pydantic_ai/test_pydantic_ai.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integrations/pydantic_ai/test_pydantic_ai.py b/tests/integrations/pydantic_ai/test_pydantic_ai.py index 20fe927b83..26673f2a87 100644 --- a/tests/integrations/pydantic_ai/test_pydantic_ai.py +++ b/tests/integrations/pydantic_ai/test_pydantic_ai.py @@ -526,7 +526,6 @@ async def test_agent_run_stream_events( ) as events: async for _ in events: pass - yield else: async for _ in test_agent.run_stream_events( ["Message demonstrating the absence of truncation.", "Test input"] From 91cea6cd8924a6bc892dd9a2097f97ae1b1507fa Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Thu, 21 May 2026 16:20:08 +0200 Subject: [PATCH 3/4] fix else branch --- tests/integrations/pydantic_ai/test_pydantic_ai.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/integrations/pydantic_ai/test_pydantic_ai.py b/tests/integrations/pydantic_ai/test_pydantic_ai.py index 26673f2a87..29ecae39b2 100644 --- a/tests/integrations/pydantic_ai/test_pydantic_ai.py +++ b/tests/integrations/pydantic_ai/test_pydantic_ai.py @@ -523,8 +523,8 @@ async def test_agent_run_stream_events( if PYDANTIC_VERSION > (2,): async with test_agent.run_stream_events( ["Message demonstrating the absence of truncation.", "Test input"] - ) as events: - async for _ in events: + ) as stream_events: + async for _ in stream_events: pass else: async for _ in test_agent.run_stream_events( @@ -551,8 +551,13 @@ async def test_agent_run_stream_events( else: events = capture_events() - async for _ in test_agent.run_stream_events("Test input"): - pass + if PYDANTIC_VERSION > (2,): + async with test_agent.run_stream_events("Test input") as stream_events: + async for _ in stream_events: + pass + else: + async for _ in test_agent.run_stream_events("Test input"): + pass (transaction,) = events From c0b7e299d4dad2a2987c1fbf11c0d0eecd9b9fcb Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Thu, 21 May 2026 17:20:12 +0200 Subject: [PATCH 4/4] rename version const --- tests/integrations/pydantic_ai/test_pydantic_ai.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integrations/pydantic_ai/test_pydantic_ai.py b/tests/integrations/pydantic_ai/test_pydantic_ai.py index 29ecae39b2..68a08c6949 100644 --- a/tests/integrations/pydantic_ai/test_pydantic_ai.py +++ b/tests/integrations/pydantic_ai/test_pydantic_ai.py @@ -19,7 +19,7 @@ from sentry_sdk.integrations.pydantic_ai.spans.utils import _set_usage_data from sentry_sdk.utils import package_version -PYDANTIC_VERSION = package_version("pydantic-ai") +PYDANTIC_AI_VERSION = package_version("pydantic-ai") @pytest.fixture @@ -520,7 +520,7 @@ async def test_agent_run_stream_events( if stream_gen_ai_spans: items = capture_items("transaction", "span") - if PYDANTIC_VERSION > (2,): + if PYDANTIC_AI_VERSION > (2,): async with test_agent.run_stream_events( ["Message demonstrating the absence of truncation.", "Test input"] ) as stream_events: @@ -551,7 +551,7 @@ async def test_agent_run_stream_events( else: events = capture_events() - if PYDANTIC_VERSION > (2,): + if PYDANTIC_AI_VERSION > (2,): async with test_agent.run_stream_events("Test input") as stream_events: async for _ in stream_events: pass