bpo-30570: Fix segfault on buildbots caused by stack overflow from recursion in tests (GH-29258)


* Don't stackoveflow on debug builds

* Also catch the pickletester case
(cherry picked from commit d56375a0dd4cee162081b173310298a3d32af293)

Co-authored-by: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index 3e2c781..f13d42f 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -2383,7 +2383,8 @@ def test_bad_getattr(self):
         # Issue #3514: crash when there is an infinite loop in __getattr__
         x = BadGetattr()
         for proto in protocols:
-            self.assertRaises(RuntimeError, self.dumps, x, proto)
+            with support.infinite_recursion():
+                self.assertRaises(RuntimeError, self.dumps, x, proto)
 
     def test_reduce_bad_iterator(self):
         # Issue4176: crash when 4th and 5th items of __reduce__()