diff options
author | Thomas Grainger <tagrain@gmail.com> | 2024-12-22 12:46:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-22 12:46:02 (GMT) |
commit | b66a4ad9fc32b63da2ba10db24cbc8f4e29f781a (patch) | |
tree | 56ee40916343692ad37843d7a6c3d343aaae64a1 /Lib | |
parent | 228f275737615cc9be713a8c3f9325b359bf8aec (diff) | |
download | cpython-b66a4ad9fc32b63da2ba10db24cbc8f4e29f781a.zip cpython-b66a4ad9fc32b63da2ba10db24cbc8f4e29f781a.tar.gz cpython-b66a4ad9fc32b63da2ba10db24cbc8f4e29f781a.tar.bz2 |
gh-127949: fix resource warnings in `test_tasks.py` (#128172)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_asyncio/test_tasks.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py index 5b8979a..7d6d056 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): |