mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-22815: Print unexpected successes in summary in TextTestResult (GH-30138)
This commit is contained in:
parent
a23ab7b6d8
commit
1944434b44
3 changed files with 40 additions and 8 deletions
|
@ -142,6 +142,12 @@ class TextTestResult(result.TestResult):
|
||||||
self.stream.flush()
|
self.stream.flush()
|
||||||
self.printErrorList('ERROR', self.errors)
|
self.printErrorList('ERROR', self.errors)
|
||||||
self.printErrorList('FAIL', self.failures)
|
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):
|
def printErrorList(self, flavour, errors):
|
||||||
for test, err in errors:
|
for test, err in errors:
|
||||||
|
|
|
@ -61,6 +61,17 @@ class Test_TestProgram(unittest.TestCase):
|
||||||
pass
|
pass
|
||||||
def testFail(self):
|
def testFail(self):
|
||||||
raise AssertionError
|
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):
|
class FooBarLoader(unittest.TestLoader):
|
||||||
"""Test loader that returns a suite containing FooBar."""
|
"""Test loader that returns a suite containing FooBar."""
|
||||||
|
@ -111,9 +122,13 @@ class Test_TestProgram(unittest.TestCase):
|
||||||
testRunner=unittest.TextTestRunner(stream=stream),
|
testRunner=unittest.TextTestRunner(stream=stream),
|
||||||
testLoader=self.FooBarLoader())
|
testLoader=self.FooBarLoader())
|
||||||
self.assertTrue(hasattr(program, 'result'))
|
self.assertTrue(hasattr(program, 'result'))
|
||||||
self.assertIn('\nFAIL: testFail ', stream.getvalue())
|
out = stream.getvalue()
|
||||||
self.assertTrue(stream.getvalue().endswith('\n\nFAILED (failures=1)\n'))
|
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):
|
def test_Exit(self):
|
||||||
stream = BufferedWriter()
|
stream = BufferedWriter()
|
||||||
|
@ -124,9 +139,13 @@ class Test_TestProgram(unittest.TestCase):
|
||||||
testRunner=unittest.TextTestRunner(stream=stream),
|
testRunner=unittest.TextTestRunner(stream=stream),
|
||||||
exit=True,
|
exit=True,
|
||||||
testLoader=self.FooBarLoader())
|
testLoader=self.FooBarLoader())
|
||||||
self.assertIn('\nFAIL: testFail ', stream.getvalue())
|
out = stream.getvalue()
|
||||||
self.assertTrue(stream.getvalue().endswith('\n\nFAILED (failures=1)\n'))
|
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):
|
def test_ExitAsDefault(self):
|
||||||
stream = BufferedWriter()
|
stream = BufferedWriter()
|
||||||
|
@ -136,8 +155,13 @@ class Test_TestProgram(unittest.TestCase):
|
||||||
argv=["foobar"],
|
argv=["foobar"],
|
||||||
testRunner=unittest.TextTestRunner(stream=stream),
|
testRunner=unittest.TextTestRunner(stream=stream),
|
||||||
testLoader=self.FooBarLoader())
|
testLoader=self.FooBarLoader())
|
||||||
self.assertIn('\nFAIL: testFail ', stream.getvalue())
|
out = stream.getvalue()
|
||||||
self.assertTrue(stream.getvalue().endswith('\n\nFAILED (failures=1)\n'))
|
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):
|
class InitialisableProgram(unittest.TestProgram):
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Print unexpected successes together with failures and errors in summary in
|
||||||
|
:class:`unittest.TextTestResult`.
|
Loading…
Add table
Add a link
Reference in a new issue