diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index 7581adc8fc272b..c33c0ae22379ce 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -831,7 +831,8 @@ def check_limit(prefix, repeated): details = "Compiling ({!r} + {!r} * {})".format( prefix, repeated, depth) with self.assertRaises(RecursionError, msg=details): - ast.parse(broken) + with support.infinite_recursion(): + ast.parse(broken) check_limit("a", "()") check_limit("a", ".b")