]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-139951: Test on GC collection disabled if threshold is zero (GH-140304...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 21 Oct 2025 15:44:23 +0000 (17:44 +0200)
committerGitHub <noreply@github.com>
Tue, 21 Oct 2025 15:44:23 +0000 (08:44 -0700)
gh-139951: Test on GC collection disabled if threshold is zero (GH-140304)
(cherry picked from commit 5d0abb69715b9638f26c896444643055ec2ef038)

Co-authored-by: Mikhail Efimov <efimov.mikhail@gmail.com>
Lib/test/test_gc.py

index 3e7dda3bac21137c51a19a051c1ea74604d475b2..81577470c5831c42b8447ed9db3dd4535ab9d0d6 100644 (file)
@@ -1524,6 +1524,20 @@ class GCTogglingTests(unittest.TestCase):
         finally:
             gc.enable()
 
+    # Ensure that setting *threshold0* to zero disables collection.
+    @gc_threshold(0)
+    def test_threshold_zero(self):
+        junk = []
+        i = 0
+        detector = GC_Detector()
+        while not detector.gc_happened:
+            i += 1
+            if i > 50000:
+                break
+            junk.append([])  # this may eventually trigger gc (if it is enabled)
+
+        self.assertEqual(i, 50001)
+
 
 class PythonFinalizationTests(unittest.TestCase):
     def test_ast_fini(self):