Skip to content

Commit

Permalink
pythongh-113980: Fix resource warnings in test_asyncgen (pythonGH-113984
Browse files Browse the repository at this point in the history
)
  • Loading branch information
serhiy-storchaka authored and aisk committed Feb 11, 2024
1 parent bb56e58 commit 42f449d
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions Lib/test/test_asyncgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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():
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit 42f449d

Please sign in to comment.