bpo-44515: handle non-refcounted GC in contextlib tests (GH-26910) (GH-27379)

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit a2c45e5bcf)

Co-authored-by: Nick Coghlan <ncoghlan@gmail.com>
This commit is contained in:
Miss Islington (bot) 2021-07-26 14:21:36 -07:00 committed by GitHub
parent 3dc88ff845
commit 0ea5e0d792
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 6 deletions

View file

@ -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 @@ async def aclose(self):
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, [])