]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-120544: Add `else: fail()` to tests where exception is expected (GH-120545...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 15 Jun 2024 11:54:07 +0000 (13:54 +0200)
committerGitHub <noreply@github.com>
Sat, 15 Jun 2024 11:54:07 +0000 (12:54 +0100)
gh-120544: Add `else: fail()` to tests where exception is expected (GH-120545)
(cherry picked from commit 42ebdd83bb194f054fe5a10b3caa0c3a95be3679)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Lib/test/test_exceptions.py
Lib/test/test_unittest/test_case.py

index 3138f50076f1df002a3a1f0c0f1c39b4b9096ce4..7e8e058f5b9a403d86090d37e104e763fbdf639a 100644 (file)
@@ -1836,6 +1836,8 @@ class NameErrorTests(unittest.TestCase):
         except self.failureException:
             with support.captured_stderr() as err:
                 sys.__excepthook__(*sys.exc_info())
+        else:
+            self.fail("assertRaisesRegex should have failed.")
 
         self.assertIn("aab", err.getvalue())
 
index ed5eb5609a5dd10ff26ba42b82f38102c9df561e..82a442a04e635ee05b9b0d388eb162e793fb7b0f 100644 (file)
@@ -1132,6 +1132,8 @@ test case
             # need to remove the first line of the error message
             error = str(e).split('\n', 1)[1]
             self.assertEqual(sample_text_error, error)
+        else:
+            self.fail(f'{self.failureException} not raised')
 
     def testAssertEqualSingleLine(self):
         sample_text = "laden swallows fly slowly"
@@ -1148,6 +1150,8 @@ test case
             # need to remove the first line of the error message
             error = str(e).split('\n', 1)[1]
             self.assertEqual(sample_text_error, error)
+        else:
+            self.fail(f'{self.failureException} not raised')
 
     def testAssertEqualwithEmptyString(self):
         '''Verify when there is an empty string involved, the diff output
@@ -1165,6 +1169,8 @@ test case
             # need to remove the first line of the error message
             error = str(e).split('\n', 1)[1]
             self.assertEqual(sample_text_error, error)
+        else:
+            self.fail(f'{self.failureException} not raised')
 
     def testAssertEqualMultipleLinesMissingNewlineTerminator(self):
         '''Verifying format of diff output from assertEqual involving strings
@@ -1185,6 +1191,8 @@ test case
             # need to remove the first line of the error message
             error = str(e).split('\n', 1)[1]
             self.assertEqual(sample_text_error, error)
+        else:
+            self.fail(f'{self.failureException} not raised')
 
     def testAssertEqualMultipleLinesMismatchedNewlinesTerminators(self):
         '''Verifying format of diff output from assertEqual involving strings
@@ -1208,6 +1216,8 @@ test case
             # need to remove the first line of the error message
             error = str(e).split('\n', 1)[1]
             self.assertEqual(sample_text_error, error)
+        else:
+            self.fail(f'{self.failureException} not raised')
 
     def testEqualityBytesWarning(self):
         if sys.flags.bytes_warning: