11import asyncio
22import os
3+ import sys
34from collections import defaultdict
45from concurrent .futures import ThreadPoolExecutor
56from time import sleep
@@ -1816,6 +1817,7 @@ async def root_function():
18161817
18171818
18181819@pytest .mark .asyncio
1820+ @pytest .mark .skipif (sys .version_info < (3 , 11 ), reason = "requires python3.11 or higher" )
18191821async def test_async_generator_context_preservation_with_trace_hierarchy ():
18201822 """Test that async generators maintain proper parent-child span relationships"""
18211823 langfuse = get_client ()
@@ -1878,13 +1880,14 @@ async def parent_function():
18781880
18791881
18801882@pytest .mark .asyncio
1881- async def test_sync_generator_exception_handling_with_context ():
1882- """Test that exceptions in sync generators are properly handled while preserving context"""
1883+ @pytest .mark .skipif (sys .version_info < (3 , 11 ), reason = "requires python3.11 or higher" )
1884+ async def test_async_generator_exception_handling_with_context ():
1885+ """Test that exceptions in async generators are properly handled while preserving context"""
18831886 langfuse = get_client ()
18841887 mock_trace_id = langfuse .create_trace_id ()
18851888
18861889 @observe (name = "failing_generator" )
1887- def failing_generator ():
1890+ async def failing_generator ():
18881891 current_span = trace .get_current_span ()
18891892 # Verify we have valid context even when exception occurs
18901893 assert (
@@ -1893,6 +1896,7 @@ def failing_generator():
18931896 )
18941897
18951898 yield "first_item"
1899+ await asyncio .sleep (0.001 )
18961900 raise ValueError ("Generator failure test" )
18971901 yield "never_reached" # This should never execute
18981902
@@ -1905,7 +1909,7 @@ async def root_function():
19051909
19061910 items = []
19071911 with pytest .raises (ValueError , match = "Generator failure test" ):
1908- for item in generator :
1912+ async for item in generator :
19091913 items .append (item )
19101914
19111915 langfuse .flush ()
0 commit comments