https://github.com/python/cpython/commit/e02c15b3f13d9d83032ada72c6773f8a3b2d34dc
commit: e02c15b3f13d9d83032ada72c6773f8a3b2d34dc
branch: main
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2024-01-12T17:30:26+02:00
summary:

gh-113980: Fix resource warnings in test_asyncgen (GH-113984)

files:
M Lib/test/test_asyncgen.py

diff --git a/Lib/test/test_asyncgen.py b/Lib/test/test_asyncgen.py
index 7fa0a85100a581..39605dca3886c8 100644
--- a/Lib/test/test_asyncgen.py
+++ b/Lib/test/test_asyncgen.py
@@ -379,7 +379,10 @@ async def async_gen_wrapper():
 
     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 @@ async def gen():
             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 @@ async def main():
         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 @@ async def main():
         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():

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to