bpo-26552: Fixed case where failing asyncio.ensure_future did not close the coroutine (#30288)

This commit is contained in:
Kumar Aditya 2022-01-29 03:54:35 +05:30 committed by GitHub
parent 36f538c809
commit 24cc6411ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 3 deletions

View file

@ -18,7 +18,7 @@ from test import support
from test.support.script_helper import assert_python_ok
from test.support import os_helper
from test.support import socket_helper
import warnings
MOCK_ANY = mock.ANY
@ -796,6 +796,17 @@ class BaseEventLoopTests(test_utils.TestCase):
task._log_destroy_pending = False
coro.close()
def test_create_task_error_closes_coro(self):
async def test():
pass
loop = asyncio.new_event_loop()
loop.close()
with warnings.catch_warnings(record=True) as w:
with self.assertRaises(RuntimeError):
asyncio.ensure_future(test(), loop=loop)
self.assertEqual(len(w), 0)
def test_create_named_task_with_default_factory(self):
async def test():
pass