File tree 1 file changed +29
-4
lines changed
1 file changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -57,12 +57,37 @@ async def __anext__(self):
57
57
return 1
58
58
59
59
async def callback (v ):
60
- raise RuntimeError
60
+ raise RuntimeError ()
61
61
62
62
inner = Inner ()
63
63
outer = map_async_iterable (inner , callback )
64
- it = outer .__aiter__ ()
65
- assert not inner .closed
66
64
with raises (RuntimeError ):
67
- await it .__anext__ ()
65
+ async for _ in outer :
66
+ pass
68
67
assert inner .closed
68
+
69
+ @mark .asyncio
70
+ async def test_inner_exit_on_callback_err ():
71
+ """
72
+ Test that a custom iterator with aclose() gets an aclose() call
73
+ when the callback errors and the outer iterator aborts.
74
+ """
75
+
76
+ inner_exit = False
77
+
78
+ async def inner ():
79
+ nonlocal inner_exit
80
+ try :
81
+ while True :
82
+ yield 1
83
+ except GeneratorExit :
84
+ inner_exit = True
85
+
86
+ async def callback (v ):
87
+ raise RuntimeError
88
+
89
+ outer = map_async_iterable (inner (), callback )
90
+ with raises (RuntimeError ):
91
+ async for _ in outer :
92
+ pass
93
+ assert inner_exit
You can’t perform that action at this time.
0 commit comments