diff --git a/Lib/test/test_asyncgen.py b/Lib/test/test_asyncgen.py index e12a94253f478a..f6184c0cab4694 100644 --- a/Lib/test/test_asyncgen.py +++ b/Lib/test/test_asyncgen.py @@ -382,8 +382,7 @@ def test_async_gen_3_arg_deprecation_warning(self): async def gen(): yield 123 - with warnings.catch_warnings(): - warnings.filterwarnings("ignore", category=DeprecationWarning) + with self.assertWarns(DeprecationWarning): gen().athrow(GeneratorExit, GeneratorExit(), None) def test_async_gen_api_01(self): diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py index 7e3ce02d6adb49..a3fabbb0545fa6 100644 --- a/Lib/test/test_asyncio/test_futures.py +++ b/Lib/test/test_asyncio/test_futures.py @@ -620,6 +620,8 @@ def test_future_stop_iteration_args(self): def test_future_iter_throw(self): fut = self._new_future(loop=self.loop) fi = iter(fut) + with self.assertWarns(DeprecationWarning): + fi.throw(Exception, Exception("zebra"), None) with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=DeprecationWarning) self.assertRaises(TypeError, fi.throw, diff --git a/Lib/test/test_coroutines.py b/Lib/test/test_coroutines.py index 4df8730157a8bf..9a2279d353ffa4 100644 --- a/Lib/test/test_coroutines.py +++ b/Lib/test/test_coroutines.py @@ -712,6 +712,13 @@ async def foo(): aw.throw(ZeroDivisionError()) self.assertEqual(N, 102) + coro = foo() + aw = coro.__await__() + next(aw) + with self.assertRaises(ZeroDivisionError): + with self.assertWarns(DeprecationWarning): + aw.throw(ZeroDivisionError, ZeroDivisionError(), None) + def test_func_11(self): async def func(): pass coro = func() diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py index a1a41b1c326b50..fb2d9ced0633f1 100644 --- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -342,6 +342,15 @@ def generator(): with self.assertRaises(StopIteration): gen.throw(E) + def test_gen_3_arg_deprecation_warning(self): + def g(): + yield 42 + + gen = g() + with self.assertWarns(DeprecationWarning): + with self.assertRaises(TypeError): + gen.throw(TypeError, TypeError(24), None) + def test_stopiteration_error(self): # See also PEP 479.