mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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
3 changed files with 13 additions and 6 deletions
|
@ -1,7 +1,7 @@
|
|||
import asyncio
|
||||
from contextlib import (
|
||||
asynccontextmanager, AbstractAsyncContextManager,
|
||||
AsyncExitStack, nullcontext, aclosing)
|
||||
AsyncExitStack, nullcontext, aclosing, contextmanager)
|
||||
import functools
|
||||
from test import support
|
||||
import unittest
|
||||
|
@ -357,14 +357,17 @@ class AclosingTestCase(unittest.TestCase):
|
|||
async def test_aclosing_bpo41229(self):
|
||||
state = []
|
||||
|
||||
class Resource:
|
||||
def __del__(self):
|
||||
@contextmanager
|
||||
def sync_resource():
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
state.append(1)
|
||||
|
||||
async def agenfunc():
|
||||
r = Resource()
|
||||
yield -1
|
||||
yield -2
|
||||
with sync_resource():
|
||||
yield -1
|
||||
yield -2
|
||||
|
||||
x = agenfunc()
|
||||
self.assertEqual(state, [])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue