Skip to content

Commit bd6f0d3

Browse files
authored
[3.10] bpo-11105: reduce the recursion limit for tests. (GH-26607)
(cherry picked from commit e58d762) Co-authored-by: Batuhan Taskaya <[email protected]>
1 parent 7518556 commit bd6f0d3

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Lib/test/support/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,3 +1982,13 @@ def skip_if_broken_multiprocessing_synchronize():
19821982
synchronize.Lock(ctx=None)
19831983
except OSError as exc:
19841984
raise unittest.SkipTest(f"broken multiprocessing SemLock: {exc!r}")
1985+
1986+
1987+
@contextlib.contextmanager
1988+
def infinite_recursion(max_depth=75):
1989+
original_depth = sys.getrecursionlimit()
1990+
try:
1991+
sys.setrecursionlimit(max_depth)
1992+
yield
1993+
finally:
1994+
sys.setrecursionlimit(original_depth)

Lib/test/test_ast.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,15 +1101,17 @@ def test_recursion_direct(self):
11011101
e = ast.UnaryOp(op=ast.Not(), lineno=0, col_offset=0)
11021102
e.operand = e
11031103
with self.assertRaises(RecursionError):
1104-
compile(ast.Expression(e), "<test>", "eval")
1104+
with support.infinite_recursion():
1105+
compile(ast.Expression(e), "<test>", "eval")
11051106

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

11141116

11151117
class ASTValidatorTests(unittest.TestCase):

0 commit comments

Comments
 (0)