mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	gh-120544: Add else: fail() to tests where exception is expected (#120545)
				
					
				
			This commit is contained in:
		
							parent
							
								
									d4039d3f6f
								
							
						
					
					
						commit
						42ebdd83bb
					
				
					 2 changed files with 12 additions and 0 deletions
				
			
		|  | @ -1859,6 +1859,8 @@ def f(): | ||||||
|         except self.failureException: |         except self.failureException: | ||||||
|             with support.captured_stderr() as err: |             with support.captured_stderr() as err: | ||||||
|                 sys.__excepthook__(*sys.exc_info()) |                 sys.__excepthook__(*sys.exc_info()) | ||||||
|  |         else: | ||||||
|  |             self.fail("assertRaisesRegex should have failed.") | ||||||
| 
 | 
 | ||||||
|         self.assertIn("aab", err.getvalue()) |         self.assertIn("aab", err.getvalue()) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1151,6 +1151,8 @@ def testAssertMultiLineEqual(self): | ||||||
|             # need to remove the first line of the error message |             # need to remove the first line of the error message | ||||||
|             error = str(e).split('\n', 1)[1] |             error = str(e).split('\n', 1)[1] | ||||||
|             self.assertEqual(sample_text_error, error) |             self.assertEqual(sample_text_error, error) | ||||||
|  |         else: | ||||||
|  |             self.fail(f'{self.failureException} not raised') | ||||||
| 
 | 
 | ||||||
|     def testAssertEqualSingleLine(self): |     def testAssertEqualSingleLine(self): | ||||||
|         sample_text = "laden swallows fly slowly" |         sample_text = "laden swallows fly slowly" | ||||||
|  | @ -1167,6 +1169,8 @@ def testAssertEqualSingleLine(self): | ||||||
|             # need to remove the first line of the error message |             # need to remove the first line of the error message | ||||||
|             error = str(e).split('\n', 1)[1] |             error = str(e).split('\n', 1)[1] | ||||||
|             self.assertEqual(sample_text_error, error) |             self.assertEqual(sample_text_error, error) | ||||||
|  |         else: | ||||||
|  |             self.fail(f'{self.failureException} not raised') | ||||||
| 
 | 
 | ||||||
|     def testAssertEqualwithEmptyString(self): |     def testAssertEqualwithEmptyString(self): | ||||||
|         '''Verify when there is an empty string involved, the diff output |         '''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 |             # need to remove the first line of the error message | ||||||
|             error = str(e).split('\n', 1)[1] |             error = str(e).split('\n', 1)[1] | ||||||
|             self.assertEqual(sample_text_error, error) |             self.assertEqual(sample_text_error, error) | ||||||
|  |         else: | ||||||
|  |             self.fail(f'{self.failureException} not raised') | ||||||
| 
 | 
 | ||||||
|     def testAssertEqualMultipleLinesMissingNewlineTerminator(self): |     def testAssertEqualMultipleLinesMissingNewlineTerminator(self): | ||||||
|         '''Verifying format of diff output from assertEqual involving strings |         '''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 |             # need to remove the first line of the error message | ||||||
|             error = str(e).split('\n', 1)[1] |             error = str(e).split('\n', 1)[1] | ||||||
|             self.assertEqual(sample_text_error, error) |             self.assertEqual(sample_text_error, error) | ||||||
|  |         else: | ||||||
|  |             self.fail(f'{self.failureException} not raised') | ||||||
| 
 | 
 | ||||||
|     def testAssertEqualMultipleLinesMismatchedNewlinesTerminators(self): |     def testAssertEqualMultipleLinesMismatchedNewlinesTerminators(self): | ||||||
|         '''Verifying format of diff output from assertEqual involving strings |         '''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 |             # need to remove the first line of the error message | ||||||
|             error = str(e).split('\n', 1)[1] |             error = str(e).split('\n', 1)[1] | ||||||
|             self.assertEqual(sample_text_error, error) |             self.assertEqual(sample_text_error, error) | ||||||
|  |         else: | ||||||
|  |             self.fail(f'{self.failureException} not raised') | ||||||
| 
 | 
 | ||||||
|     def testEqualityBytesWarning(self): |     def testEqualityBytesWarning(self): | ||||||
|         if sys.flags.bytes_warning: |         if sys.flags.bytes_warning: | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Nikita Sobolev
						Nikita Sobolev