@@ -30,23 +30,7 @@ def wrapper(*args, **kwargs):
3030 return wrapper
3131
3232
33- class TestAbstractAsyncContextManager (unittest .IsolatedAsyncioTestCase ):
34-
35- def test_async_test_self_test (self ):
36- class _async_yield :
37- def __init__ (self , v ):
38- self .v = v
39-
40- def __await__ (self ):
41- return (yield self .v )
42-
43- @_async_test
44- async def do_not_stop_coro ():
45- while True :
46- await _async_yield (None )
47-
48- with self .assertRaisesRegex (AssertionError , "coroutine did not stop" ):
49- do_not_stop_coro ()
33+ class TestAbstractAsyncContextManager (unittest .TestCase ):
5034
5135 @_async_test
5236 async def test_enter (self ):
@@ -60,6 +44,7 @@ async def __aexit__(self, *args):
6044 async with manager as context :
6145 self .assertIs (manager , context )
6246
47+ @_async_test
6348 async def test_slots (self ):
6449 class DefaultAsyncContextManager (AbstractAsyncContextManager ):
6550 __slots__ = ()
@@ -71,6 +56,7 @@ async def __aexit__(self, *args):
7156 manager = DefaultAsyncContextManager ()
7257 manager .var = 42
7358
59+ @_async_test
7460 async def test_async_gen_propagates_generator_exit (self ):
7561 # A regression test for https://bugs.python.org/issue33786.
7662
@@ -121,8 +107,9 @@ class NoneAexit(ManagerFromScratch):
121107 self .assertFalse (issubclass (NoneAexit , AbstractAsyncContextManager ))
122108
123109
124- class AsyncContextManagerTestCase (unittest .IsolatedAsyncioTestCase ):
110+ class AsyncContextManagerTestCase (unittest .TestCase ):
125111
112+ @_async_test
126113 async def test_contextmanager_plain (self ):
127114 state = []
128115 @asynccontextmanager
@@ -136,6 +123,7 @@ async def woohoo():
136123 state .append (x )
137124 self .assertEqual (state , [1 , 42 , 999 ])
138125
126+ @_async_test
139127 async def test_contextmanager_finally (self ):
140128 state = []
141129 @asynccontextmanager
@@ -153,6 +141,7 @@ async def woohoo():
153141 raise ZeroDivisionError ()
154142 self .assertEqual (state , [1 , 42 , 999 ])
155143
144+ @_async_test
156145 async def test_contextmanager_traceback (self ):
157146 @asynccontextmanager
158147 async def f ():
@@ -208,6 +197,7 @@ class StopAsyncIterationSubclass(StopAsyncIteration):
208197 self .assertEqual (frames [0 ].name , 'test_contextmanager_traceback' )
209198 self .assertEqual (frames [0 ].line , 'raise stop_exc' )
210199
200+ @_async_test
211201 async def test_contextmanager_no_reraise (self ):
212202 @asynccontextmanager
213203 async def whee ():
@@ -217,6 +207,7 @@ async def whee():
217207 # Calling __aexit__ should not result in an exception
218208 self .assertFalse (await ctx .__aexit__ (TypeError , TypeError ("foo" ), None ))
219209
210+ @_async_test
220211 async def test_contextmanager_trap_yield_after_throw (self ):
221212 @asynccontextmanager
222213 async def whoo ():
@@ -232,6 +223,7 @@ async def whoo():
232223 # The "gen" attribute is an implementation detail.
233224 self .assertFalse (ctx .gen .ag_suspended )
234225
226+ @_async_test
235227 async def test_contextmanager_trap_no_yield (self ):
236228 @asynccontextmanager
237229 async def whoo ():
@@ -241,6 +233,7 @@ async def whoo():
241233 with self .assertRaises (RuntimeError ):
242234 await ctx .__aenter__ ()
243235
236+ @_async_test
244237 async def test_contextmanager_trap_second_yield (self ):
245238 @asynccontextmanager
246239 async def whoo ():
@@ -254,6 +247,7 @@ async def whoo():
254247 # The "gen" attribute is an implementation detail.
255248 self .assertFalse (ctx .gen .ag_suspended )
256249
250+ @_async_test
257251 async def test_contextmanager_non_normalised (self ):
258252 @asynccontextmanager
259253 async def whoo ():
@@ -267,6 +261,7 @@ async def whoo():
267261 with self .assertRaises (SyntaxError ):
268262 await ctx .__aexit__ (RuntimeError , None , None )
269263
264+ @_async_test
270265 async def test_contextmanager_except (self ):
271266 state = []
272267 @asynccontextmanager
@@ -284,6 +279,7 @@ async def woohoo():
284279 raise ZeroDivisionError (999 )
285280 self .assertEqual (state , [1 , 42 , 999 ])
286281
282+ @_async_test
287283 async def test_contextmanager_except_stopiter (self ):
288284 @asynccontextmanager
289285 async def woohoo ():
@@ -310,6 +306,7 @@ class StopAsyncIterationSubclass(StopAsyncIteration):
310306 else :
311307 self .fail (f'{ stop_exc } was suppressed' )
312308
309+ @_async_test
313310 async def test_contextmanager_wrap_runtimeerror (self ):
314311 @asynccontextmanager
315312 async def woohoo ():
@@ -354,12 +351,14 @@ def test_contextmanager_doc_attrib(self):
354351 self .assertEqual (baz .__doc__ , "Whee!" )
355352
356353 @support .requires_docstrings
354+ @_async_test
357355 async def test_instance_docstring_given_cm_docstring (self ):
358356 baz = self ._create_contextmanager_attribs ()(None )
359357 self .assertEqual (baz .__doc__ , "Whee!" )
360358 async with baz :
361359 pass # suppress warning
362360
361+ @_async_test
363362 async def test_keywords (self ):
364363 # Ensure no keyword arguments are inhibited
365364 @asynccontextmanager
@@ -368,6 +367,7 @@ async def woohoo(self, func, args, kwds):
368367 async with woohoo (self = 11 , func = 22 , args = 33 , kwds = 44 ) as target :
369368 self .assertEqual (target , (11 , 22 , 33 , 44 ))
370369
370+ @_async_test
371371 async def test_recursive (self ):
372372 depth = 0
373373 ncols = 0
@@ -394,6 +394,7 @@ async def recursive():
394394 self .assertEqual (ncols , 10 )
395395 self .assertEqual (depth , 0 )
396396
397+ @_async_test
397398 async def test_decorator (self ):
398399 entered = False
399400
@@ -412,6 +413,7 @@ async def test():
412413 await test ()
413414 self .assertFalse (entered )
414415
416+ @_async_test
415417 async def test_decorator_with_exception (self ):
416418 entered = False
417419
@@ -434,6 +436,7 @@ async def test():
434436 await test ()
435437 self .assertFalse (entered )
436438
439+ @_async_test
437440 async def test_decorating_method (self ):
438441
439442 @asynccontextmanager
@@ -468,14 +471,15 @@ async def method(self, a, b, c=None):
468471 self .assertEqual (test .b , 2 )
469472
470473
471- class AclosingTestCase (unittest .IsolatedAsyncioTestCase ):
474+ class AclosingTestCase (unittest .TestCase ):
472475
473476 @support .requires_docstrings
474477 def test_instance_docs (self ):
475478 cm_docstring = aclosing .__doc__
476479 obj = aclosing (None )
477480 self .assertEqual (obj .__doc__ , cm_docstring )
478481
482+ @_async_test
479483 async def test_aclosing (self ):
480484 state = []
481485 class C :
@@ -487,6 +491,7 @@ async def aclose(self):
487491 self .assertEqual (x , y )
488492 self .assertEqual (state , [1 ])
489493
494+ @_async_test
490495 async def test_aclosing_error (self ):
491496 state = []
492497 class C :
@@ -500,6 +505,7 @@ async def aclose(self):
500505 1 / 0
501506 self .assertEqual (state , [1 ])
502507
508+ @_async_test
503509 async def test_aclosing_bpo41229 (self ):
504510 state = []
505511
@@ -525,7 +531,7 @@ async def agenfunc():
525531 self .assertEqual (state , [1 ])
526532
527533
528- class TestAsyncExitStack (TestBaseExitStack , unittest .IsolatedAsyncioTestCase ):
534+ class TestAsyncExitStack (TestBaseExitStack , unittest .TestCase ):
529535 class SyncAsyncExitStack (AsyncExitStack ):
530536
531537 def close (self ):
@@ -589,6 +595,7 @@ async def _exit(*args, **kwds):
589595 stack .push_async_callback (callback = _exit , arg = 3 )
590596 self .assertEqual (result , [])
591597
598+ @_async_test
592599 async def test_async_push (self ):
593600 exc_raised = ZeroDivisionError
594601 async def _expect_exc (exc_type , exc , exc_tb ):
@@ -624,6 +631,7 @@ async def __aexit__(self, *exc_details):
624631 self .assertIs (stack ._exit_callbacks [- 1 ][1 ], _expect_exc )
625632 1 / 0
626633
634+ @_async_test
627635 async def test_enter_async_context (self ):
628636 class TestCM (object ):
629637 async def __aenter__ (self ):
@@ -645,6 +653,7 @@ async def _exit():
645653
646654 self .assertEqual (result , [1 , 2 , 3 , 4 ])
647655
656+ @_async_test
648657 async def test_enter_async_context_errors (self ):
649658 class LacksEnterAndExit :
650659 pass
@@ -664,6 +673,7 @@ async def __aenter__(self):
664673 await stack .enter_async_context (LacksExit ())
665674 self .assertFalse (stack ._exit_callbacks )
666675
676+ @_async_test
667677 async def test_async_exit_exception_chaining (self ):
668678 # Ensure exception chaining matches the reference behaviour
669679 async def raise_exc (exc ):
@@ -695,6 +705,7 @@ async def suppress_exc(*exc_details):
695705 self .assertIsInstance (inner_exc , ValueError )
696706 self .assertIsInstance (inner_exc .__context__ , ZeroDivisionError )
697707
708+ @_async_test
698709 async def test_async_exit_exception_explicit_none_context (self ):
699710 # Ensure AsyncExitStack chaining matches actual nested `with` statements
700711 # regarding explicit __context__ = None.
@@ -729,6 +740,7 @@ async def my_cm_with_exit_stack():
729740 else :
730741 self .fail ("Expected IndexError, but no exception was raised" )
731742
743+ @_async_test
732744 async def test_instance_bypass_async (self ):
733745 class Example (object ): pass
734746 cm = Example ()
@@ -741,7 +753,8 @@ class Example(object): pass
741753 self .assertIs (stack ._exit_callbacks [- 1 ][1 ], cm )
742754
743755
744- class TestAsyncNullcontext (unittest .IsolatedAsyncioTestCase ):
756+ class TestAsyncNullcontext (unittest .TestCase ):
757+ @_async_test
745758 async def test_async_nullcontext (self ):
746759 class C :
747760 pass
0 commit comments