]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-94438: Fix RuntimeWarning for jump tests in test_sys_settrace (GH-111341)
authorTian Gao <gaogaotiantian@hotmail.com>
Thu, 26 Oct 2023 18:47:51 +0000 (11:47 -0700)
committerGitHub <noreply@github.com>
Thu, 26 Oct 2023 18:47:51 +0000 (11:47 -0700)
Lib/test/test_sys_settrace.py

index 6be9d3f5d0f9a7567af1e9fb7c8d7cd87d396b98..df7dd36274df2eb06d862f6326e7eb66bc21cc53 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)
 
@@ -2001,6 +2002,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)
@@ -2064,7 +2068,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:
@@ -2081,7 +2085,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: