]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.10] bpo-11105: reduce the recursion limit for tests. (GH-26607)
authorBatuhan Taskaya <batuhan@python.org>
Tue, 8 Jun 2021 17:39:30 +0000 (20:39 +0300)
committerGitHub <noreply@github.com>
Tue, 8 Jun 2021 17:39:30 +0000 (20:39 +0300)
(cherry picked from commit e58d762c1fb4ad5e021d016c80c2bc4513632d2f)

Co-authored-by: Batuhan Taskaya <batuhan@python.org>
Lib/test/support/__init__.py
Lib/test/test_ast.py

index 80f3a04fcc61803d77af19a1c9d19fcb1ee6ccc4..b9040a9ac507a4b2b8cbcf030a6dbd9a30ac2897 100644 (file)
@@ -1982,3 +1982,13 @@ def skip_if_broken_multiprocessing_synchronize():
             synchronize.Lock(ctx=None)
         except OSError as exc:
             raise unittest.SkipTest(f"broken multiprocessing SemLock: {exc!r}")
+
+
+@contextlib.contextmanager
+def infinite_recursion(max_depth=75):
+    original_depth = sys.getrecursionlimit()
+    try:
+        sys.setrecursionlimit(max_depth)
+        yield
+    finally:
+        sys.setrecursionlimit(original_depth)
index e08a965d96f76e161b752942bad35d12bd57dc5d..a44f8f551c5e0a25f5a10496c55500dd9e682060 100644 (file)
@@ -1101,7 +1101,8 @@ Module(
         e = ast.UnaryOp(op=ast.Not(), lineno=0, col_offset=0)
         e.operand = e
         with self.assertRaises(RecursionError):
-            compile(ast.Expression(e), "<test>", "eval")
+            with support.infinite_recursion():
+                compile(ast.Expression(e), "<test>", "eval")
 
     def test_recursion_indirect(self):
         e = ast.UnaryOp(op=ast.Not(), lineno=0, col_offset=0)
@@ -1109,7 +1110,8 @@ Module(
         e.operand = f
         f.operand = e
         with self.assertRaises(RecursionError):
-            compile(ast.Expression(e), "<test>", "eval")
+            with support.infinite_recursion():
+                compile(ast.Expression(e), "<test>", "eval")
 
 
 class ASTValidatorTests(unittest.TestCase):