]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44515: handle non-refcounted GC in contextlib tests (GH-26910)
authorNick Coghlan <ncoghlan@gmail.com>
Mon, 26 Jul 2021 20:57:17 +0000 (06:57 +1000)
committerGitHub <noreply@github.com>
Mon, 26 Jul 2021 20:57:17 +0000 (22:57 +0200)
Co-authored-by: Ɓukasz Langa <lukasz@langa.pl>
Lib/test/test_contextlib.py
Lib/test/test_contextlib_async.py
Misc/NEWS.d/next/Tests/2021-06-26-18-37-36.bpo-44515.e9fO6f.rst [new file with mode: 0644]

index 04720d949fee5ba8ced9d245e08dd36da14ca36e..43b8507771e25a66f8a75eb0a58abaf9964d93f9 100644 (file)
@@ -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
index 6a218f911569c920c304895556797d83a0eedf0f..74fddef3f34ec55ba666d4d4a050d5b700665ff7 100644 (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 @@ 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 (file)
index 0000000..d2867b6
--- /dev/null
@@ -0,0 +1,2 @@
+Adjust recently added contextlib tests to avoid assuming the use of a
+refcounted GC