From: Thomas Grainger Date: Sun, 22 Dec 2024 12:46:02 +0000 (+0000) Subject: gh-127949: fix resource warnings in `test_tasks.py` (#128172) X-Git-Tag: v3.14.0a4~214 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b66a4ad9fc32b63da2ba10db24cbc8f4e29f781a;p=thirdparty%2FPython%2Fcpython.git gh-127949: fix resource warnings in `test_tasks.py` (#128172) --- diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py index 5b8979a8bbd1..7d6d0564a9a9 100644 --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -2698,17 +2698,17 @@ class BaseTaskTests: initial_refcount = sys.getrefcount(obj) coro = coroutine_function() - loop = asyncio.new_event_loop() - task = asyncio.Task.__new__(asyncio.Task) + with contextlib.closing(asyncio.EventLoop()) as loop: + task = asyncio.Task.__new__(asyncio.Task) - for _ in range(5): - with self.assertRaisesRegex(RuntimeError, 'break'): - task.__init__(coro, loop=loop, context=obj, name=Break()) + for _ in range(5): + with self.assertRaisesRegex(RuntimeError, 'break'): + task.__init__(coro, loop=loop, context=obj, name=Break()) - coro.close() - del task + coro.close() + del task - self.assertEqual(sys.getrefcount(obj), initial_refcount) + self.assertEqual(sys.getrefcount(obj), initial_refcount) def add_subclass_tests(cls):