summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBatuhan Taskaya <batuhan@python.org>2021-06-08 16:55:10 (GMT)
committerGitHub <noreply@github.com>2021-06-08 16:55:10 (GMT)
commite58d762c1fb4ad5e021d016c80c2bc4513632d2f (patch)
tree4eb76e44c9d9bc6e1297a38335c91a655ea7e2a2
parent257e400a19b34c7da6e2aa500d80b54e4c4dbf6f (diff)
downloadcpython-e58d762c1fb4ad5e021d016c80c2bc4513632d2f.zip
cpython-e58d762c1fb4ad5e021d016c80c2bc4513632d2f.tar.gz
cpython-e58d762c1fb4ad5e021d016c80c2bc4513632d2f.tar.bz2
bpo-11105: reduce the recursion limit for tests (GH-26550)
-rw-r--r--Lib/test/support/__init__.py9
-rw-r--r--Lib/test/test_ast.py6
2 files changed, 13 insertions, 2 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 34a9459..d17331e 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -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)
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index 6a6f06c..5f1ee75 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -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):