]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] GH-94438: Fix RuntimeWarning for jump tests in test_sys_settrace (GH-111369)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 26 Oct 2023 22:44:47 +0000 (00:44 +0200)
committerGitHub <noreply@github.com>
Thu, 26 Oct 2023 22:44:47 +0000 (22:44 +0000)
(cherry picked from commit a254120f2f1dd99fa64f12594d1ed19c67df7d64)
Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
Lib/test/test_sys_settrace.py

index 84088d428c9cc913d095cb8a7e29021346a825ad..7e16e94aa110b20a2ee83570a292572bac966e9b 100644 (file)
@@ -9,6 +9,7 @@ from functools import wraps
 import asyncio
 from test.support import import_helper
 import contextlib
+import warnings
 
 support.requires_working_socket(module=True)
 
@@ -1970,6 +1971,9 @@ class JumpTestCase(unittest.TestCase):
                 stack.enter_context(self.assertRaisesRegex(*error))
             if warning is not None:
                 stack.enter_context(self.assertWarnsRegex(*warning))
+            else:
+                stack.enter_context(warnings.catch_warnings())
+                warnings.simplefilter('error')
             func(output)
 
         sys.settrace(None)
@@ -2033,7 +2037,7 @@ class JumpTestCase(unittest.TestCase):
         output.append(1)
         output.append(2)
 
-    @jump_test(1, 4, [5])
+    @jump_test(1, 4, [5], warning=(RuntimeWarning, unbound_locals))
     def test_jump_is_none_forwards(output):
         x = None
         if x is None:
@@ -2050,7 +2054,7 @@ class JumpTestCase(unittest.TestCase):
             output.append(5)
         output.append(6)
 
-    @jump_test(1, 4, [5])
+    @jump_test(2, 4, [5])
     def test_jump_is_not_none_forwards(output):
         x = None
         if x is not None: