@@ -195,10 +195,11 @@ def test_gc_hooks_do_not_cause_unraisable_recursionerror():
195
195
196
196
# This test is potentially flaky, because the stack usage of a function is not
197
197
# constant. Regardless, if the test passes just once that's sufficient proof that
198
- # it's not the GC (or accounting of it) that is at fault.
198
+ # it's not the GC (or accounting of it) that is at fault. Note, I haven't actually
199
+ # seen it fail/flake, but I believe it could happen in principle.
199
200
200
- # The number of cycles sufficient to reliably trigger a GC cycle , experimentally
201
- # found to be a few hundred on CPython. Multiply by 10 for safety margin.
201
+ # The number of cycles sufficient to reliably trigger GC , experimentally found
202
+ # to be a few hundred on CPython. Multiply by 10 for safety margin.
202
203
NUM_CYCLES = 5_000
203
204
204
205
def probe_depth ():
@@ -251,12 +252,16 @@ def inner_test(_):
251
252
max_depth -= 1
252
253
else :
253
254
break
254
- # Note that PyPy is a bit weird, in that it raises RecursionError at
255
- # (maxdepth - n) for small positive n, but not at exactly (maxdepth).
256
- # In general, it is really finicky to get the details right in this
257
- # test, so be careful.
258
-
259
- # Now check that the limit is unchanged with gc enabled
255
+ # Note that PyPy is a bit weird, in that it raises RecursionError at
256
+ # (maxdepth - n) for small positive n, but not at exactly (maxdepth).
257
+ # In general, it is really finicky to get the details right in this
258
+ # test, so be careful.
259
+
260
+ # Now check that the limit is unchanged with gc enabled, and also that
261
+ # leaving a few frames for the callbacks does not fail.
262
+ if hasattr (gc , "callbacks" ): # see comment above
263
+ for n in range (1 , 4 ):
264
+ gen_cycles_at_depth (max_depth - n , gc_disable = False )
260
265
gen_cycles_at_depth (max_depth , gc_disable = False )
261
266
with pytest .raises (RecursionError ):
262
267
gen_cycles_at_depth (max_depth + 1 , gc_disable = False )
0 commit comments