Skip to content

Commit 2baf6da

Browse files
committed
Add test coverage
1 parent c5dcb61 commit 2baf6da

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

tests/test_prefect.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ async def test_run_stream_in_flow(allow_model_requests: None) -> None:
747747
@flow(name='test_run_stream_in_flow')
748748
async def run_stream_workflow():
749749
async with simple_prefect_agent.run_stream('What is the capital of Mexico?') as result:
750-
return await result.get_output()
750+
return await result.get_output() # pragma: no cover
751751

752752
with flow_raises(
753753
UserError,
@@ -759,6 +759,25 @@ async def run_stream_workflow():
759759
await run_stream_workflow()
760760

761761

762+
async def test_run_stream_events_in_flow(allow_model_requests: None) -> None:
763+
"""Test that run_stream_events errors when used inside a Prefect flow."""
764+
765+
@flow(name='test_run_stream_events_in_flow')
766+
async def run_stream_events_workflow():
767+
return [
768+
event async for event in simple_prefect_agent.run_stream_events('What is the capital of Mexico?')
769+
] # pragma: no cover
770+
771+
with flow_raises(
772+
UserError,
773+
snapshot(
774+
'`agent.run_stream_events()` cannot be used inside a Prefect flow. '
775+
'Set an `event_stream_handler` on the agent and use `agent.run()` instead.'
776+
),
777+
):
778+
await run_stream_events_workflow()
779+
780+
762781
async def test_iter_in_flow(allow_model_requests: None) -> None:
763782
"""Test that iter works inside a Prefect flow."""
764783

0 commit comments

Comments
 (0)