Skip to content

Commit e58d762

Browse files
authored
bpo-11105: reduce the recursion limit for tests (GH-26550)
1 parent 257e400 commit e58d762

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Lib/test/support/__init__.py

+9
Original file line numberDiff line numberDiff line change
@@ -1999,3 +1999,12 @@ def check_disallow_instantiation(testcase, tp, *args, **kwds):
19991999
qualname = f"{name}"
20002000
msg = f"cannot create '{re.escape(qualname)}' instances"
20012001
testcase.assertRaisesRegex(TypeError, msg, tp, *args, **kwds)
2002+
2003+
@contextlib.contextmanager
2004+
def infinite_recursion(max_depth=75):
2005+
original_depth = sys.getrecursionlimit()
2006+
try:
2007+
sys.setrecursionlimit(max_depth)
2008+
yield
2009+
finally:
2010+
sys.setrecursionlimit(original_depth)

Lib/test/test_ast.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1102,15 +1102,17 @@ def test_recursion_direct(self):
11021102
e = ast.UnaryOp(op=ast.Not(), lineno=0, col_offset=0)
11031103
e.operand = e
11041104
with self.assertRaises(RecursionError):
1105-
compile(ast.Expression(e), "<test>", "eval")
1105+
with support.infinite_recursion():
1106+
compile(ast.Expression(e), "<test>", "eval")
11061107

11071108
def test_recursion_indirect(self):
11081109
e = ast.UnaryOp(op=ast.Not(), lineno=0, col_offset=0)
11091110
f = ast.UnaryOp(op=ast.Not(), lineno=0, col_offset=0)
11101111
e.operand = f
11111112
f.operand = e
11121113
with self.assertRaises(RecursionError):
1113-
compile(ast.Expression(e), "<test>", "eval")
1114+
with support.infinite_recursion():
1115+
compile(ast.Expression(e), "<test>", "eval")
11141116

11151117

11161118
class ASTValidatorTests(unittest.TestCase):

0 commit comments

Comments
 (0)