Skip to content

Commit 2cebf45

Browse files
graingertsrinivasreddy
authored andcommitted
pythongh-127949: fix resource warnings in test_tasks.py (python#128172)
1 parent a49356e commit 2cebf45

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Lib/test/test_asyncio/test_tasks.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -2698,17 +2698,17 @@ def __str__(self):
26982698
initial_refcount = sys.getrefcount(obj)
26992699

27002700
coro = coroutine_function()
2701-
loop = asyncio.new_event_loop()
2702-
task = asyncio.Task.__new__(asyncio.Task)
2701+
with contextlib.closing(asyncio.EventLoop()) as loop:
2702+
task = asyncio.Task.__new__(asyncio.Task)
27032703

2704-
for _ in range(5):
2705-
with self.assertRaisesRegex(RuntimeError, 'break'):
2706-
task.__init__(coro, loop=loop, context=obj, name=Break())
2704+
for _ in range(5):
2705+
with self.assertRaisesRegex(RuntimeError, 'break'):
2706+
task.__init__(coro, loop=loop, context=obj, name=Break())
27072707

2708-
coro.close()
2709-
del task
2708+
coro.close()
2709+
del task
27102710

2711-
self.assertEqual(sys.getrefcount(obj), initial_refcount)
2711+
self.assertEqual(sys.getrefcount(obj), initial_refcount)
27122712

27132713

27142714
def add_subclass_tests(cls):

0 commit comments

Comments
 (0)