Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e931f7b

Browse files
committed
Issue #21163: Fix "destroy pending task" warning in test_wait_errors()
1 parent f03b3c7 commit e931f7b

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

Lib/asyncio/tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,14 @@ def wait(fs, *, loop=None, timeout=None, return_when=ALL_COMPLETED):
330330
raise TypeError("expect a list of futures, not %s" % type(fs).__name__)
331331
if not fs:
332332
raise ValueError('Set of coroutines/Futures is empty.')
333+
if return_when not in (FIRST_COMPLETED, FIRST_EXCEPTION, ALL_COMPLETED):
334+
raise ValueError('Invalid return_when value: {}'.format(return_when))
333335

334336
if loop is None:
335337
loop = events.get_event_loop()
336338

337339
fs = {async(f, loop=loop) for f in set(fs)}
338340

339-
if return_when not in (FIRST_COMPLETED, FIRST_EXCEPTION, ALL_COMPLETED):
340-
raise ValueError('Invalid return_when value: {}'.format(return_when))
341341
return (yield from _wait(fs, timeout, return_when, loop))
342342

343343

Lib/test/test_asyncio/test_tasks.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,13 @@ def test_wait_errors(self):
623623
ValueError, self.loop.run_until_complete,
624624
asyncio.wait(set(), loop=self.loop))
625625

626-
self.assertRaises(
627-
ValueError, self.loop.run_until_complete,
628-
asyncio.wait([asyncio.sleep(10.0, loop=self.loop)],
629-
return_when=-1, loop=self.loop))
626+
# -1 is an invalid return_when value
627+
sleep_coro = asyncio.sleep(10.0, loop=self.loop)
628+
wait_coro = asyncio.wait([sleep_coro], return_when=-1, loop=self.loop)
629+
self.assertRaises(ValueError,
630+
self.loop.run_until_complete, wait_coro)
631+
632+
sleep_coro.close()
630633

631634
def test_wait_first_completed(self):
632635

0 commit comments

Comments
 (0)