Skip to content

Commit

Permalink
gh-127949: fix resource warnings in test_tasks.py (#128172)
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert authored Dec 22, 2024
1 parent 228f275 commit b66a4ad
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2698,17 +2698,17 @@ def __str__(self):
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):
Expand Down

0 comments on commit b66a4ad

Please sign in to comment.