Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Lib/unittest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ def printErrors(self):
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:
Expand Down
40 changes: 32 additions & 8 deletions Lib/unittest/test/test_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ def testPass(self):
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."""
Expand Down Expand Up @@ -111,9 +122,13 @@ def test_NonExit(self):
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()
Expand All @@ -124,9 +139,13 @@ def test_Exit(self):
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()
Expand All @@ -136,8 +155,13 @@ def test_ExitAsDefault(self):
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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Print unexpected successes together with failures and errors in summary in
:class:`unittest.TextTestResult`.