From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 21 Oct 2025 15:44:33 +0000 (+0200) Subject: [3.14] gh-139951: Test on GC collection disabled if threshold is zero (GH-140304... X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3d4cf3bda37ac9c0fa2b65c91caf8c5aa1df9e99;p=thirdparty%2FPython%2Fcpython.git [3.14] gh-139951: Test on GC collection disabled if threshold is zero (GH-140304) (#140362) gh-139951: Test on GC collection disabled if threshold is zero (GH-140304) (cherry picked from commit 5d0abb69715b9638f26c896444643055ec2ef038) Co-authored-by: Mikhail Efimov --- diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py index 969d290c259f..71a4f035fbb0 100644 --- a/Lib/test/test_gc.py +++ b/Lib/test/test_gc.py @@ -1501,6 +1501,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):