summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_contextlib_async.py
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2021-07-26 20:57:17 (GMT)
committerGitHub <noreply@github.com>2021-07-26 20:57:17 (GMT)
commita2c45e5bcf9d3dfff9f2699dbc161489897616b5 (patch)
tree255ece84775a01078365b4d28e14cc8184d595c7 /Lib/test/test_contextlib_async.py
parent5fdd2a14ce3f81a7db47bb79421c426dec4b25bd (diff)
downloadcpython-a2c45e5bcf9d3dfff9f2699dbc161489897616b5.zip
cpython-a2c45e5bcf9d3dfff9f2699dbc161489897616b5.tar.gz
cpython-a2c45e5bcf9d3dfff9f2699dbc161489897616b5.tar.bz2
bpo-44515: handle non-refcounted GC in contextlib tests (GH-26910)
Co-authored-by: Ɓukasz Langa <lukasz@langa.pl>
Diffstat (limited to 'Lib/test/test_contextlib_async.py')
-rw-r--r--Lib/test/test_contextlib_async.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/Lib/test/test_contextlib_async.py b/Lib/test/test_contextlib_async.py
index 6a218f9..74fddef 100644
--- a/Lib/test/test_contextlib_async.py
+++ b/Lib/test/test_contextlib_async.py
@@ -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, [])