Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.9] bpo-11105: reduce the recursion limit for tests (GH-26550). #26605

Merged
merged 1 commit into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 4 additions & 2 deletions Lib/test/test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,15 +1031,17 @@ def test_recursion_direct(self):
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)
f = ast.UnaryOp(op=ast.Not(), lineno=0, col_offset=0)
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):
Expand Down