@@ -704,6 +704,10 @@ def test_get_recursion_depth(self):
704704 code = textwrap .dedent ("""
705705 from test import support
706706 import sys
707+ try:
708+ from _testcapi import USE_STACKCHECK
709+ except ImportError:
710+ USE_STACKCHECK = False
707711
708712 def check(cond):
709713 if not cond:
@@ -728,19 +732,24 @@ def test_recursive(depth, limit):
728732 check(get_depth == depth)
729733 test_recursive(depth + 1, limit)
730734
735+ if USE_STACKCHECK:
736+ # f-string consumes 2 frames and -1 for USE_STACKCHECK
737+ IGNORE = 3
738+ else:
739+ # f-string consumes 2 frames
740+ IGNORE = 2
741+
731742 # depth up to 25
732743 with support.infinite_recursion(max_depth=25):
733744 limit = sys.getrecursionlimit()
734745 print(f"test with sys.getrecursionlimit()={limit}")
735- # Use limit-2 since f-string seems to consume 2 frames.
736- test_recursive(2, limit - 2)
746+ test_recursive(2, limit - IGNORE)
737747
738748 # depth up to 500
739749 with support.infinite_recursion(max_depth=500):
740750 limit = sys.getrecursionlimit()
741751 print(f"test with sys.getrecursionlimit()={limit}")
742- # limit-2 since f-string seems to consume 2 frames
743- test_recursive(2, limit - 2)
752+ test_recursive(2, limit - IGNORE)
744753 """ )
745754 script_helper .assert_python_ok ("-c" , code )
746755
0 commit comments