diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2021-12-26 11:22:44 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-26 11:22:44 (GMT) |
commit | 1944434b44e0118e812bf63f47b268ff6dd0c8f1 (patch) | |
tree | 2121b834a66f6787771dd60e7236b26c4a39b6cb /Lib | |
parent | a23ab7b6d8b3ae3a47747c0c4bceb2370cc48dcc (diff) | |
download | cpython-1944434b44e0118e812bf63f47b268ff6dd0c8f1.zip cpython-1944434b44e0118e812bf63f47b268ff6dd0c8f1.tar.gz cpython-1944434b44e0118e812bf63f47b268ff6dd0c8f1.tar.bz2 |
bpo-22815: Print unexpected successes in summary in TextTestResult (GH-30138)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/unittest/runner.py | 6 | ||||
-rw-r--r-- | Lib/unittest/test/test_program.py | 40 |
2 files changed, 38 insertions, 8 deletions
diff --git a/Lib/unittest/runner.py b/Lib/unittest/runner.py index 120ee6a..6678adb 100644 --- a/Lib/unittest/runner.py +++ b/Lib/unittest/runner.py @@ -142,6 +142,12 @@ class TextTestResult(result.TestResult): self.stream.flush() self.printErrorList('ERROR', self.errors) self.printErrorList('FAIL', self.failures) + unexpectedSuccesses = getattr(self, 'unexpectedSuccesses', ()) + if unexpectedSuccesses: + self.stream.writeln(self.separator1) + for test in unexpectedSuccesses: + self.stream.writeln(f"UNEXPECTED SUCCESS: {self.getDescription(test)}") + self.stream.flush() def printErrorList(self, flavour, errors): for test, err in errors: diff --git a/Lib/unittest/test/test_program.py b/Lib/unittest/test/test_program.py index 2bf7dd7..f7049fb 100644 --- a/Lib/unittest/test/test_program.py +++ b/Lib/unittest/test/test_program.py @@ -61,6 +61,17 @@ class Test_TestProgram(unittest.TestCase): pass def testFail(self): raise AssertionError + def testError(self): + 1/0 + @unittest.skip('skipping') + def testSkipped(self): + raise AssertionError + @unittest.expectedFailure + def testExpectedFailure(self): + raise AssertionError + @unittest.expectedFailure + def testUnexpectedSuccess(self): + pass class FooBarLoader(unittest.TestLoader): """Test loader that returns a suite containing FooBar.""" @@ -111,9 +122,13 @@ class Test_TestProgram(unittest.TestCase): testRunner=unittest.TextTestRunner(stream=stream), testLoader=self.FooBarLoader()) self.assertTrue(hasattr(program, 'result')) - self.assertIn('\nFAIL: testFail ', stream.getvalue()) - self.assertTrue(stream.getvalue().endswith('\n\nFAILED (failures=1)\n')) - + out = stream.getvalue() + self.assertIn('\nFAIL: testFail ', out) + self.assertIn('\nERROR: testError ', out) + self.assertIn('\nUNEXPECTED SUCCESS: testUnexpectedSuccess ', out) + expected = ('\n\nFAILED (failures=1, errors=1, skipped=1, ' + 'expected failures=1, unexpected successes=1)\n') + self.assertTrue(out.endswith(expected)) def test_Exit(self): stream = BufferedWriter() @@ -124,9 +139,13 @@ class Test_TestProgram(unittest.TestCase): testRunner=unittest.TextTestRunner(stream=stream), exit=True, testLoader=self.FooBarLoader()) - self.assertIn('\nFAIL: testFail ', stream.getvalue()) - self.assertTrue(stream.getvalue().endswith('\n\nFAILED (failures=1)\n')) - + out = stream.getvalue() + self.assertIn('\nFAIL: testFail ', out) + self.assertIn('\nERROR: testError ', out) + self.assertIn('\nUNEXPECTED SUCCESS: testUnexpectedSuccess ', out) + expected = ('\n\nFAILED (failures=1, errors=1, skipped=1, ' + 'expected failures=1, unexpected successes=1)\n') + self.assertTrue(out.endswith(expected)) def test_ExitAsDefault(self): stream = BufferedWriter() @@ -136,8 +155,13 @@ class Test_TestProgram(unittest.TestCase): argv=["foobar"], testRunner=unittest.TextTestRunner(stream=stream), testLoader=self.FooBarLoader()) - self.assertIn('\nFAIL: testFail ', stream.getvalue()) - self.assertTrue(stream.getvalue().endswith('\n\nFAILED (failures=1)\n')) + out = stream.getvalue() + self.assertIn('\nFAIL: testFail ', out) + self.assertIn('\nERROR: testError ', out) + self.assertIn('\nUNEXPECTED SUCCESS: testUnexpectedSuccess ', out) + expected = ('\n\nFAILED (failures=1, errors=1, skipped=1, ' + 'expected failures=1, unexpected successes=1)\n') + self.assertTrue(out.endswith(expected)) class InitialisableProgram(unittest.TestProgram): |