Skip to content

Commit 89abf3b

Browse files
graingertmiss-islington
authored andcommitted
gh-127949: fix resource warnings in test_tasks.py (GH-128172)
(cherry picked from commit b66a4ad) Co-authored-by: Thomas Grainger <[email protected]>
1 parent b2dbc4f commit 89abf3b

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Lib/test/test_asyncio/test_tasks.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2499,17 +2499,17 @@ def __str__(self):
24992499
initial_refcount = sys.getrefcount(obj)
25002500

25012501
coro = coroutine_function()
2502-
loop = asyncio.new_event_loop()
2503-
task = asyncio.Task.__new__(asyncio.Task)
2502+
with contextlib.closing(asyncio.EventLoop()) as loop:
2503+
task = asyncio.Task.__new__(asyncio.Task)
25042504

2505-
for _ in range(5):
2506-
with self.assertRaisesRegex(RuntimeError, 'break'):
2507-
task.__init__(coro, loop=loop, context=obj, name=Break())
2505+
for _ in range(5):
2506+
with self.assertRaisesRegex(RuntimeError, 'break'):
2507+
task.__init__(coro, loop=loop, context=obj, name=Break())
25082508

2509-
coro.close()
2510-
del task
2509+
coro.close()
2510+
del task
25112511

2512-
self.assertEqual(sys.getrefcount(obj), initial_refcount)
2512+
self.assertEqual(sys.getrefcount(obj), initial_refcount)
25132513

25142514

25152515
def add_subclass_tests(cls):

0 commit comments

Comments
 (0)