]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-130080: fix warnings in tests (#131400)
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>
Tue, 18 Mar 2025 12:33:46 +0000 (12:33 +0000)
committerGitHub <noreply@github.com>
Tue, 18 Mar 2025 12:33:46 +0000 (12:33 +0000)
Lib/test/test_compile.py
Lib/test/test_functools.py
Lib/test/test_grammar.py
Lib/test/test_sys_settrace.py
Lib/test/test_unparse.py
Lib/test/test_yield_from.py

index f5d757d8fc72c99e93e09723b3fda41f35057e10..b1dc770fe4d4111e6435831117a41672f2fe438c 100644 (file)
@@ -2415,7 +2415,9 @@ class TestStackSizeStability(unittest.TestCase):
             script = """def func():\n""" + i * snippet
             if async_:
                 script = "async " + script
-            code = compile(script, "<script>", "exec")
+            with warnings.catch_warnings():
+                warnings.simplefilter('ignore', SyntaxWarning)
+                code = compile(script, "<script>", "exec")
             exec(code, ns, ns)
             return ns['func'].__code__
 
index 5e04b15e014ea26babb36a1f91c7841f51e4bfce..fe096fa075865fff52ae8e2305423e835a239780 100644 (file)
@@ -3011,7 +3011,8 @@ class TestSingleDispatch(unittest.TestCase):
                 try:
                     yield str(arg)
                 finally:
-                    return 'Done'
+                    pass
+                return 'Done'
 
             @classmethod_friendly_decorator
             @classmethod
@@ -3027,7 +3028,8 @@ class TestSingleDispatch(unittest.TestCase):
                 try:
                     yield str(arg)
                 finally:
-                    return 'Done'
+                    pass
+                return 'Done'
 
             @functools.singledispatchmethod
             @classmethod_friendly_decorator
index 994c8a0e15ac40555841cb6c5ec46a7395f602f8..bde0b45b3ceb931cd4b68a07c9466d1486703dfc 100644 (file)
@@ -917,56 +917,59 @@ class GrammarTests(unittest.TestCase):
         check_syntax_error(self, "class foo:return 1")
 
     def test_break_in_finally(self):
-        count = 0
-        while count < 2:
-            count += 1
-            try:
-                pass
-            finally:
-                break
-        self.assertEqual(count, 1)
+        with warnings.catch_warnings():
+            warnings.simplefilter('ignore', SyntaxWarning)
 
-        count = 0
-        while count < 2:
-            count += 1
-            try:
-                continue
-            finally:
-                break
-        self.assertEqual(count, 1)
+            count = 0
+            while count < 2:
+                count += 1
+                try:
+                    pass
+                finally:
+                    break
+            self.assertEqual(count, 1)
 
-        count = 0
-        while count < 2:
-            count += 1
-            try:
-                1/0
-            finally:
-                break
-        self.assertEqual(count, 1)
+            count = 0
+            while count < 2:
+                count += 1
+                try:
+                    continue
+                finally:
+                    break
+            self.assertEqual(count, 1)
 
-        for count in [0, 1]:
+            count = 0
+            while count < 2:
+                count += 1
+                try:
+                    1/0
+                finally:
+                    break
+            self.assertEqual(count, 1)
+
+            for count in [0, 1]:
+                self.assertEqual(count, 0)
+                try:
+                    pass
+                finally:
+                    break
             self.assertEqual(count, 0)
-            try:
-                pass
-            finally:
-                break
-        self.assertEqual(count, 0)
 
-        for count in [0, 1]:
+            for count in [0, 1]:
+                self.assertEqual(count, 0)
+                try:
+                    continue
+                finally:
+                    break
             self.assertEqual(count, 0)
-            try:
-                continue
-            finally:
-                break
-        self.assertEqual(count, 0)
 
-        for count in [0, 1]:
+            for count in [0, 1]:
+                self.assertEqual(count, 0)
+                try:
+                    1/0
+                finally:
+                    break
             self.assertEqual(count, 0)
-            try:
-                1/0
-            finally:
-                break
-        self.assertEqual(count, 0)
 
     def test_continue_in_finally(self):
         count = 0
index e528c6a9c69d282272c25b76490252406563d7c5..b3685a91c57ee7afa64aed2e49115b15ff241724 100644 (file)
@@ -920,20 +920,28 @@ class TraceTestCase(unittest.TestCase):
 
         def func():
             try:
-                2/0
-            except IndexError:
-                4
-            finally:
-                return 6
+                try:
+                    2/0
+                except IndexError:
+                    5
+                finally:
+                    7
+            except:
+                pass
+            return 10
 
         self.run_and_compare(func,
             [(0, 'call'),
              (1, 'line'),
              (2, 'line'),
-             (2, 'exception'),
              (3, 'line'),
-             (6, 'line'),
-             (6, 'return')])
+             (3, 'exception'),
+             (4, 'line'),
+             (7, 'line'),
+             (8, 'line'),
+             (9, 'line'),
+             (10, 'line'),
+             (10, 'return')])
 
     def test_finally_with_conditional(self):
 
@@ -2228,21 +2236,6 @@ class JumpTestCase(unittest.TestCase):
             output.append(11)
         output.append(12)
 
-    @jump_test(5, 11, [2, 4], (ValueError, 'comes after the current code block'))
-    def test_no_jump_over_return_try_finally_in_finally_block(output):
-        try:
-            output.append(2)
-        finally:
-            output.append(4)
-            output.append(5)
-            return
-            try:
-                output.append(8)
-            finally:
-                output.append(10)
-            pass
-        output.append(12)
-
     @jump_test(3, 4, [1], (ValueError, 'after'))
     def test_no_jump_infinite_while_loop(output):
         output.append(1)
@@ -2766,7 +2759,7 @@ class JumpTestCase(unittest.TestCase):
         finally:
             output.append(4)
             output.append(5)
-            return
+        return
         output.append(7)
 
     @jump_test(7, 4, [1, 6], (ValueError, 'into'))
index 9efea1e037f44764a55884bcaff13324d50d7399..686649a520880e1a5742b5c2c1e4530cbcc517fd 100644 (file)
@@ -5,6 +5,7 @@ import test.support
 import pathlib
 import random
 import tokenize
+import warnings
 import ast
 from test.support.ast_helper import ASTTestMixin
 
@@ -839,13 +840,16 @@ class DirectoryTestCase(ASTTestCase):
         return items
 
     def test_files(self):
-        for item in self.files_to_test():
-            if test.support.verbose:
-                print(f"Testing {item.absolute()}")
+        with warnings.catch_warnings():
+            warnings.simplefilter('ignore', SyntaxWarning)
 
-            with self.subTest(filename=item):
-                source = read_pyfile(item)
-                self.check_ast_roundtrip(source)
+            for item in self.files_to_test():
+                if test.support.verbose:
+                    print(f"Testing {item.absolute()}")
+
+                with self.subTest(filename=item):
+                    source = read_pyfile(item)
+                    self.check_ast_roundtrip(source)
 
 
 if __name__ == "__main__":
index b90e15e20027dcd75e9cc8b000bf08ea2b47ef41..06edc18df149443410f93529fbe2fd1c4e33c0e5 100644 (file)
@@ -1520,8 +1520,9 @@ class TestInterestingEdgeCases(unittest.TestCase):
             try:
                 yield yielded_first
                 yield yielded_second
-            finally:
-                return returned
+            except:
+                pass
+            return returned
 
         def outer():
             return (yield from inner())