diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-07-26 21:21:36 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-26 21:21:36 (GMT) |
commit | 0ea5e0d792a85b435ef299319dcd52e59f535cb1 (patch) | |
tree | d810228d6b0a808efae86dcb69cbb151bd4ef539 | |
parent | 3dc88ff845091ea6a8e2e559e13cb0294b088e39 (diff) | |
download | cpython-0ea5e0d792a85b435ef299319dcd52e59f535cb1.zip cpython-0ea5e0d792a85b435ef299319dcd52e59f535cb1.tar.gz cpython-0ea5e0d792a85b435ef299319dcd52e59f535cb1.tar.bz2 |
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 a2c45e5bcf9d3dfff9f2699dbc161489897616b5)
Co-authored-by: Nick Coghlan <ncoghlan@gmail.com>
-rw-r--r-- | Lib/test/test_contextlib.py | 2 | ||||
-rw-r--r-- | Lib/test/test_contextlib_async.py | 15 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Tests/2021-06-26-18-37-36.bpo-44515.e9fO6f.rst | 2 |
3 files changed, 13 insertions, 6 deletions
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py index e6500da..5a08065 100644 --- a/Lib/test/test_contextlib.py +++ b/Lib/test/test_contextlib.py @@ -231,6 +231,8 @@ def woohoo(): def woohoo(a, b): a = weakref.ref(a) b = weakref.ref(b) + # Allow test to work with a non-refcounted GC + support.gc_collect() self.assertIsNone(a()) self.assertIsNone(b()) yield diff --git a/Lib/test/test_contextlib_async.py b/Lib/test/test_contextlib_async.py index 9cb40d1..603162e 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, []) diff --git a/Misc/NEWS.d/next/Tests/2021-06-26-18-37-36.bpo-44515.e9fO6f.rst b/Misc/NEWS.d/next/Tests/2021-06-26-18-37-36.bpo-44515.e9fO6f.rst new file mode 100644 index 0000000..d2867b6 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2021-06-26-18-37-36.bpo-44515.e9fO6f.rst @@ -0,0 +1,2 @@ +Adjust recently added contextlib tests to avoid assuming the use of a +refcounted GC |