8000 [3.9] bpo-11105: reduce the recursion limit for tests. (GH-26605) · python/cpython@87f5022 · GitHub
[go: up one dir, main page]

Skip to content

Commit 87f5022

Browse files
authored
[3.9] bpo-11105: reduce the recursion limit for tests. (GH-26605)
(cherry picked from commit e58d762) Co-authored-by: Batuhan Taskaya <batuhan@python.org>
1 parent d5f8bd6 commit 87f5022

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
@@ -3199,3 +3199,13 @@ def skip_if_broken_multiprocessing_synchronize():
31993199
synchronize.Lock(ctx=None)
32003200
except OSError as exc:
32013201
raise unittest.SkipTest(f"broken multiprocessing SemLock: {exc!r}")
3202+
3203+
3204+
@contextlib.contextmanager
3205+
def infinite_recursion(max_depth=75):
3206+
original_depth = sys.getrecursionlimit()
3207+
try:
3208+
sys.setrecursionlimit(max_depth)
3209+
yield
3210+
finally:
3211+
sys.setrecursionlimit(original_depth)

Lib/test/test_ast.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,15 +1031,17 @@ def test_recursion_direct(self):
10311031
e = ast.UnaryOp(op=ast.Not(), lineno=0, col_offset=0)
10321032
e.operand = e
10331033
with self.assertRaises(RecursionError):
1034-
compile(ast.Expression(e), "<test>", "eval")
1034+
with support.infinite_recursion():
1035+
compile(ast.Expression(e), "<test>", "eval")
10351036

10361037
def test_recursion_indirect(self):
10371038
e = ast.UnaryOp(op=ast.Not(), lineno=0, col_offset=0)
10381039
f = ast.UnaryOp(op=ast.Not(), lineno=0, col_offset=0)
10391040
e.operand = f
10401041
f.operand = e
10411042
with self.assertRaises(RecursionError):
1042-
compile(ast.Expression(e), "<test>", "eval")
1043+
with support.infinite_recursion():
1044+
compile(ast.Expression(e), "<test>", "eval")
10431045

10441046

10451047
class ASTValidatorTests(unittest.TestCase):

0 commit comments

Comments
 (0)
0