]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-113980: Fix resource warnings in test_asyncgen (GH-113984)
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 12 Jan 2024 15:30:26 +0000 (17:30 +0200)
committerGitHub <noreply@github.com>
Fri, 12 Jan 2024 15:30:26 +0000 (17:30 +0200)
Lib/test/test_asyncgen.py

index 7fa0a85100a581baba4a7ec7fa11764d3e779d9a..39605dca3886c8f69f877c6efea7fd23c8b2f5fe 100644 (file)
@@ -379,7 +379,10 @@ class AsyncGenTest(unittest.TestCase):
 
     def test_async_gen_exception_12(self):
         async def gen():
-            await anext(me)
+            with self.assertWarnsRegex(RuntimeWarning,
+                    f"coroutine method 'asend' of '{gen.__qualname__}' "
+                    f"was never awaited"):
+                await anext(me)
             yield 123
 
         me = gen()
@@ -395,7 +398,12 @@ class AsyncGenTest(unittest.TestCase):
             yield 123
 
         with self.assertWarns(DeprecationWarning):
-            gen().athrow(GeneratorExit, GeneratorExit(), None)
+            x = gen().athrow(GeneratorExit, GeneratorExit(), None)
+        with self.assertWarnsRegex(RuntimeWarning,
+                f"coroutine method 'athrow' of '{gen.__qualname__}' "
+                f"was never awaited"):
+            del x
+            gc_collect()
 
     def test_async_gen_api_01(self):
         async def gen():
@@ -1564,6 +1572,11 @@ class AsyncGenAsyncioTest(unittest.TestCase):
         self.assertIsInstance(message['exception'], ZeroDivisionError)
         self.assertIn('unhandled exception during asyncio.run() shutdown',
                       message['message'])
+        with self.assertWarnsRegex(RuntimeWarning,
+                f"coroutine method 'aclose' of '{async_iterate.__qualname__}' "
+                f"was never awaited"):
+            del message, messages
+            gc_collect()
 
     def test_async_gen_expression_01(self):
         async def arange(n):
@@ -1617,6 +1630,10 @@ class AsyncGenAsyncioTest(unittest.TestCase):
         asyncio.run(main())
 
         self.assertEqual([], messages)
+        with self.assertWarnsRegex(RuntimeWarning,
+                f"coroutine method 'aclose' of '{async_iterate.__qualname__}' "
+                f"was never awaited"):
+            gc_collect()
 
     def test_async_gen_await_same_anext_coro_twice(self):
         async def async_iterate():