]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-111808: Make the default value for `test.support.infinite_recursion()` conditional...
authorBrett Cannon <brett@python.org>
Fri, 17 Nov 2023 23:52:11 +0000 (15:52 -0800)
committerGitHub <noreply@github.com>
Fri, 17 Nov 2023 23:52:11 +0000 (15:52 -0800)
Co-authored-by: Victor Stinner <vstinner@python.org>
Lib/test/support/__init__.py
Lib/test/test_richcmp.py
Lib/test/test_typing.py
Misc/NEWS.d/next/Tests/2023-11-17-15-20-41.gh-issue-111808.jtIayt.rst [new file with mode: 0644]

index d476ba50df17cbeee27e74e357d4e888e18519d4..bb9f998db4622b559c85fd7c1231f6f2f5a4bdfc 100644 (file)
@@ -2120,13 +2120,21 @@ def set_recursion_limit(limit):
     finally:
         sys.setrecursionlimit(original_limit)
 
-def infinite_recursion(max_depth=100):
+def infinite_recursion(max_depth=None):
     """Set a lower limit for tests that interact with infinite recursions
     (e.g test_ast.ASTHelpers_Test.test_recursion_direct) since on some
     debug windows builds, due to not enough functions being inlined the
     stack size might not handle the default recursion limit (1000). See
     bpo-11105 for details."""
-    if max_depth < 3:
+    if max_depth is None:
+        if not python_is_optimized() or Py_DEBUG:
+            # Python built without compiler optimizations or in debug mode
+            # usually consumes more stack memory per function call.
+            # Unoptimized number based on what works under a WASI debug build.
+            max_depth = 50
+        else:
+            max_depth = 100
+    elif max_depth < 3:
         raise ValueError("max_depth must be at least 3, got {max_depth}")
     depth = get_recursion_depth()
     depth = max(depth - 1, 1)  # Ignore infinite_recursion() frame.
index 5f449cdc05c6bae1afdae79a5edc8b00f7051479..6fb31c80d7e6707ab19d196b54cce6691ac48eb7 100644 (file)
@@ -221,7 +221,7 @@ class MiscTest(unittest.TestCase):
             self.assertRaises(Exc, func, Bad())
 
     @support.no_tracing
-    @support.infinite_recursion(25)
+    @support.infinite_recursion()
     def test_recursion(self):
         # Check that comparison for recursive objects fails gracefully
         from collections import UserList
index 8681e7efba3244fa08a61280058e6d30a6100574..2b5f34b4b92e0c90adfb395bc03a5821aa5c53fd 100644 (file)
@@ -5621,7 +5621,7 @@ class ForwardRefTests(BaseTestCase):
         def cmp(o1, o2):
             return o1 == o2
 
-        with infinite_recursion(25):  # magic number, small but reasonable
+        with infinite_recursion():
             r1 = namespace1()
             r2 = namespace2()
             self.assertIsNot(r1, r2)
diff --git a/Misc/NEWS.d/next/Tests/2023-11-17-15-20-41.gh-issue-111808.jtIayt.rst b/Misc/NEWS.d/next/Tests/2023-11-17-15-20-41.gh-issue-111808.jtIayt.rst
new file mode 100644 (file)
index 0000000..36151d4
--- /dev/null
@@ -0,0 +1,4 @@
+Make the default value of ``test.support.infinite_recursion()`` to be
+conditional based on whether optimizations were used when compiling the
+interpreter. This helps with platforms like WASI whose stack size is greatly
+restricted in debug builds.