]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.9] bpo-11105: reduce the recursion limit for tests. (GH-26605)
authorBatuhan Taskaya <batuhan@python.org>
Tue, 8 Jun 2021 17:39:47 +0000 (20:39 +0300)
committerGitHub <noreply@github.com>
Tue, 8 Jun 2021 17:39:47 +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 aee3737ffc4097884ea38e77ef54f5d7228a6583..229e1ac0a2a22ef1d69bdf7a17781b2402a3d7fa 100644 (file)
@@ -3199,3 +3199,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 b229921f5c07c5eaeb52551d2a1bd979cdd280be..c3e3be6335340b91379166ab9c2fecdd398d0e60 100644 (file)
@@ -1031,7 +1031,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)
@@ -1039,7 +1040,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):