File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -212,6 +212,19 @@ def woohoo():
212212 self .assertEqual (state , ['enter' ])
213213 self .assertEqual (state , ['enter' , 'exit' ])
214214
215+ def test_contextmanager_preserves_generator_attributeerror (self ):
216+ # Only the attribute deletion is guarded: an AttributeError raised
217+ # by the generator itself must propagate unchanged.
218+ exc = AttributeError ('generator failure' )
219+ @contextmanager
220+ def woohoo ():
221+ raise exc
222+ yield
223+ with self .assertRaises (AttributeError ) as cm :
224+ with woohoo ():
225+ pass
226+ self .assertIs (cm .exception , exc )
227+
215228 def test_contextmanager_trap_second_yield (self ):
216229 @contextmanager
217230 def whoo ():
Original file line number Diff line number Diff line change @@ -254,6 +254,20 @@ async def woohoo():
254254 self .assertEqual (state , ['enter' ])
255255 self .assertEqual (state , ['enter' , 'exit' ])
256256
257+ @_async_test
258+ async def test_contextmanager_preserves_generator_attributeerror (self ):
259+ # Only the attribute deletion is guarded: an AttributeError raised
260+ # by the generator itself must propagate unchanged.
261+ exc = AttributeError ('generator failure' )
262+ @asynccontextmanager
263+ async def woohoo ():
264+ raise exc
265+ yield
266+ with self .assertRaises (AttributeError ) as cm :
267+ async with woohoo ():
268+ pass
269+ self .assertIs (cm .exception , exc )
270+
257271 @_async_test
258272 async def test_contextmanager_trap_second_yield (self ):
259273 @asynccontextmanager
You can’t perform that action at this time.
0 commit comments