]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-11105: reduce the recursion limit for tests (GH-26550)
authorBatuhan Taskaya <batuhan@python.org>
Tue, 8 Jun 2021 16:55:10 +0000 (19:55 +0300)
committerGitHub <noreply@github.com>
Tue, 8 Jun 2021 16:55:10 +0000 (19:55 +0300)
Lib/test/support/__init__.py
Lib/test/test_ast.py

index 34a9459b518fabd4e522a56b8b2912b6b150fd42..d17331e6e89b7d022b7af35f2905381eeceff50e 100644 (file)
@@ -1999,3 +1999,12 @@ def check_disallow_instantiation(testcase, tp, *args, **kwds):
         qualname = f"{name}"
     msg = f"cannot create '{re.escape(qualname)}' instances"
     testcase.assertRaisesRegex(TypeError, msg, tp, *args, **kwds)
+
+@contextlib.contextmanager
+def infinite_recursion(max_depth=75):
+    original_depth = sys.getrecursionlimit()
+    try:
+        sys.setrecursionlimit(max_depth)
+        yield
+    finally:
+        sys.setrecursionlimit(original_depth)
index 6a6f06c835037a55dc1920f255d8700d1de68730..5f1ee75c8bddcbddfe72f0257bb887b8be6f8b91 100644 (file)
@@ -1102,7 +1102,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)
@@ -1110,7 +1111,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):