Skip to content

Commit 924a6ce

Browse files
[3.13] gh-127949: fix resource warnings in test_tasks.py (GH-128172) (#131805)
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 7f7fc54 commit 924a6ce

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
@@ -2694,17 +2694,17 @@ def __str__(self):
26942694
initial_refcount = sys.getrefcount(obj)
26952695

26962696
coro = coroutine_function()
2697-
loop = asyncio.new_event_loop()
2698-
task = asyncio.Task.__new__(asyncio.Task)
2697+
with contextlib.closing(asyncio.EventLoop()) as loop:
2698+
task = asyncio.Task.__new__(asyncio.Task)
26992699

2700-
for _ in range(5):
2701-
with self.assertRaisesRegex(RuntimeError, 'break'):
2702-
task.__init__(coro, loop=loop, context=obj, name=Break())
2700+
for _ in range(5):
2701+
with self.assertRaisesRegex(RuntimeError, 'break'):
2702+
task.__init__(coro, loop=loop, context=obj, name=Break())
27032703

2704-
coro.close()
2705-
del task
2704+
coro.close()
2705+
del task
27062706

2707-
self.assertEqual(sys.getrefcount(obj), initial_refcount)
2707+
self.assertEqual(sys.getrefcount(obj), initial_refcount)
27082708

27092709

27102710
def add_subclass_tests(cls):

0 commit comments

Comments
 (0)