Skip to content

Commit 21397ec

Browse files
test(pydantic-ai): Support Agent.run_stream_events() returning a context manager (#6322)
1 parent 7cc0278 commit 21397ec

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

tests/integrations/pydantic_ai/test_pydantic_ai.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
from sentry_sdk.integrations.pydantic_ai import PydanticAIIntegration
1818
from sentry_sdk.integrations.pydantic_ai.spans.ai_client import _set_input_messages
1919
from sentry_sdk.integrations.pydantic_ai.spans.utils import _set_usage_data
20+
from sentry_sdk.utils import package_version
21+
22+
PYDANTIC_AI_VERSION = package_version("pydantic-ai")
2023

2124

2225
@pytest.fixture
@@ -517,10 +520,17 @@ async def test_agent_run_stream_events(
517520
if stream_gen_ai_spans:
518521
items = capture_items("transaction", "span")
519522

520-
async for _ in test_agent.run_stream_events(
521-
["Message demonstrating the absence of truncation.", "Test input"]
522-
):
523-
pass
523+
if PYDANTIC_AI_VERSION > (2,):
524+
async with test_agent.run_stream_events(
525+
["Message demonstrating the absence of truncation.", "Test input"]
526+
) as stream_events:
527+
async for _ in stream_events:
528+
pass
529+
else:
530+
async for _ in test_agent.run_stream_events(
531+
["Message demonstrating the absence of truncation.", "Test input"]
532+
):
533+
pass
524534

525535
# Verify transaction
526536
(transaction,) = (item.payload for item in items if item.type == "transaction")
@@ -541,8 +551,13 @@ async def test_agent_run_stream_events(
541551
else:
542552
events = capture_events()
543553

544-
async for _ in test_agent.run_stream_events("Test input"):
545-
pass
554+
if PYDANTIC_AI_VERSION > (2,):
555+
async with test_agent.run_stream_events("Test input") as stream_events:
556+
async for _ in stream_events:
557+
pass
558+
else:
559+
async for _ in test_agent.run_stream_events("Test input"):
560+
pass
546561

547562
(transaction,) = events
548563

0 commit comments

Comments
 (0)