https://github.com/python/cpython/commit/42ebdd83bb194f054fe5a10b3caa0c3a95be3679
commit: 42ebdd83bb194f054fe5a10b3caa0c3a95be3679
branch: main
author: Nikita Sobolev <[email protected]>
committer: sobolevn <[email protected]>
date: 2024-06-15T10:33:14Z
summary:
gh-120544: Add `else: fail()` to tests where exception is expected (#120545)
files:
M Lib/test/test_exceptions.py
M Lib/test/test_unittest/test_case.py
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 9460d1f1c864b9..e4f2e3a97b8bb8 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -1859,6 +1859,8 @@ def f():
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())
diff --git a/Lib/test/test_unittest/test_case.py
b/Lib/test/test_unittest/test_case.py
index 17420909402107..b4b2194a09cf9f 100644
--- a/Lib/test/test_unittest/test_case.py
+++ b/Lib/test/test_unittest/test_case.py
@@ -1151,6 +1151,8 @@ def testAssertMultiLineEqual(self):
# 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"
@@ -1167,6 +1169,8 @@ def testAssertEqualSingleLine(self):
# 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
@@ -1184,6 +1188,8 @@ def testAssertEqualwithEmptyString(self):
# 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
@@ -1204,6 +1210,8 @@ def
testAssertEqualMultipleLinesMissingNewlineTerminator(self):
# 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
@@ -1227,6 +1235,8 @@ def
testAssertEqualMultipleLinesMismatchedNewlinesTerminators(self):
# 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:
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]