Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-113980: Fix resource warnings in test_asyncgen #113984

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading