mirror of https://github.com/python/cpython
bpo-44515: handle non-refcounted GC in contextlib tests (GH-26910)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
parent
5fdd2a14ce
commit
a2c45e5bcf
|
@ -231,6 +231,8 @@ def woohoo():
|
||||||
def woohoo(a, b):
|
def woohoo(a, b):
|
||||||
a = weakref.ref(a)
|
a = weakref.ref(a)
|
||||||
b = weakref.ref(b)
|
b = weakref.ref(b)
|
||||||
|
# Allow test to work with a non-refcounted GC
|
||||||
|
support.gc_collect()
|
||||||
self.assertIsNone(a())
|
self.assertIsNone(a())
|
||||||
self.assertIsNone(b())
|
self.assertIsNone(b())
|
||||||
yield
|
yield
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
from contextlib import (
|
from contextlib import (
|
||||||
asynccontextmanager, AbstractAsyncContextManager,
|
asynccontextmanager, AbstractAsyncContextManager,
|
||||||
AsyncExitStack, nullcontext, aclosing)
|
AsyncExitStack, nullcontext, aclosing, contextmanager)
|
||||||
import functools
|
import functools
|
||||||
from test import support
|
from test import support
|
||||||
import unittest
|
import unittest
|
||||||
|
@ -357,14 +357,17 @@ class AclosingTestCase(unittest.TestCase):
|
||||||
async def test_aclosing_bpo41229(self):
|
async def test_aclosing_bpo41229(self):
|
||||||
state = []
|
state = []
|
||||||
|
|
||||||
class Resource:
|
@contextmanager
|
||||||
def __del__(self):
|
def sync_resource():
|
||||||
|
try:
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
state.append(1)
|
state.append(1)
|
||||||
|
|
||||||
async def agenfunc():
|
async def agenfunc():
|
||||||
r = Resource()
|
with sync_resource():
|
||||||
yield -1
|
yield -1
|
||||||
yield -2
|
yield -2
|
||||||
|
|
||||||
x = agenfunc()
|
x = agenfunc()
|
||||||
self.assertEqual(state, [])
|
self.assertEqual(state, [])
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Adjust recently added contextlib tests to avoid assuming the use of a
|
||||||
|
refcounted GC
|
Loading…
Reference in New Issue