mirror of
https://github.com/python/cpython.git
synced 2026-04-14 07:41:00 +00:00
[3.12] gh-127949: fix resource warnings in test_tasks.py (GH-128172) (#131806)
* gh-127949: fix resource warnings in `test_tasks.py` (GH-128172)
(cherry picked from commit b66a4ad9fc)
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
This commit is contained in:
parent
940c937c13
commit
d4ddc03e56
1 changed files with 9 additions and 8 deletions
|
|
@ -1,6 +1,7 @@
|
|||
"""Tests for tasks.py."""
|
||||
|
||||
import collections
|
||||
import contextlib
|
||||
import contextvars
|
||||
import gc
|
||||
import io
|
||||
|
|
@ -2499,17 +2500,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.new_event_loop()) 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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue