@@ -31,11 +31,6 @@ def __new__(cls, *args, **kwargs):
3131 return C
3232 ContainerNoGC = None
3333
34- try :
35- import _testinternalcapi
36- except ImportError :
37- _testinternalcapi = None
38-
3934### Support code
4035###############################################################################
4136
@@ -1135,7 +1130,6 @@ def setUp(self):
11351130 def tearDown (self ):
11361131 gc .disable ()
11371132
1138- @unittest .skipIf (_testinternalcapi is None , "requires _testinternalcapi" )
11391133 @requires_gil_enabled ("Free threading does not support incremental GC" )
11401134 # Use small increments to emulate longer running process in a shorter time
11411135 @gc_threshold (200 , 10 )
@@ -1173,15 +1167,20 @@ def make_ll(depth):
11731167 enabled = gc .isenabled ()
11741168 gc .enable ()
11751169 olds = []
1176- initial_heap_size = _testinternalcapi .get_tracked_heap_size ()
11771170 for i in range (20_000 ):
11781171 newhead = make_ll (20 )
11791172 count += 20
11801173 newhead .surprise = head
11811174 olds .append (newhead )
11821175 if len (olds ) == 20 :
1183- new_objects = _testinternalcapi .get_tracked_heap_size () - initial_heap_size
1184- self .assertLess (new_objects , 27_000 , f"Heap growing. Reached limit after { i } iterations" )
1176+ stats = gc .get_stats ()
1177+ young = stats [0 ]
1178+ incremental = stats [1 ]
1179+ old = stats [2 ]
1180+ collected = young ['collected' ] + incremental ['collected' ] + old ['collected' ]
1181+ count += CORRECTION
1182+ live = count - collected
1183+ self .assertLess (live , 25000 )
11851184 del olds [:]
11861185 if not enabled :
11871186 gc .disable ()
@@ -1323,8 +1322,7 @@ def test_refcount_errors(self):
13231322 from test.support import gc_collect, SuppressCrashReport
13241323
13251324 a = [1, 2, 3]
1326- b = [a, a]
1327- a.append(b)
1325+ b = [a]
13281326
13291327 # Avoid coredump when Py_FatalError() calls abort()
13301328 SuppressCrashReport().__enter__()
@@ -1334,8 +1332,6 @@ def test_refcount_errors(self):
13341332 # (to avoid deallocating it):
13351333 import ctypes
13361334 ctypes.pythonapi.Py_DecRef(ctypes.py_object(a))
1337- del a
1338- del b
13391335
13401336 # The garbage collector should now have a fatal error
13411337 # when it reaches the broken object
@@ -1364,7 +1360,7 @@ def test_refcount_errors(self):
13641360 self .assertRegex (stderr ,
13651361 br'object type name: list' )
13661362 self .assertRegex (stderr ,
1367- br'object repr : \[1, 2, 3, \[\[...\], \[...\]\] \]' )
1363+ br'object repr : \[1, 2, 3\]' )
13681364
13691365
13701366class GCTogglingTests (unittest .TestCase ):
0 commit comments