mirror of
https://github.com/python/cpython.git
synced 2025-12-10 19:10:59 +00:00
bpo-25894: Always report skipped and failed subtests separately (GH-28082)
* In default mode output separate characters for skipped and failed subtests. * In verbose mode output separate lines (including description) for skipped and failed subtests. * In verbose mode output test description for errors in test cleanup.
This commit is contained in:
parent
ab327f2929
commit
f0f29f328d
3 changed files with 253 additions and 113 deletions
|
|
@ -5,6 +5,7 @@ import time
|
|||
import warnings
|
||||
|
||||
from . import result
|
||||
from .case import _SubTest
|
||||
from .signals import registerResult
|
||||
|
||||
__unittest = True
|
||||
|
|
@ -40,6 +41,7 @@ class TextTestResult(result.TestResult):
|
|||
self.showAll = verbosity > 1
|
||||
self.dots = verbosity == 1
|
||||
self.descriptions = descriptions
|
||||
self._newline = True
|
||||
|
||||
def getDescription(self, test):
|
||||
doc_first_line = test.shortDescription()
|
||||
|
|
@ -54,11 +56,39 @@ class TextTestResult(result.TestResult):
|
|||
self.stream.write(self.getDescription(test))
|
||||
self.stream.write(" ... ")
|
||||
self.stream.flush()
|
||||
self._newline = False
|
||||
|
||||
def _write_status(self, test, status):
|
||||
is_subtest = isinstance(test, _SubTest)
|
||||
if is_subtest or self._newline:
|
||||
if not self._newline:
|
||||
self.stream.writeln()
|
||||
if is_subtest:
|
||||
self.stream.write(" ")
|
||||
self.stream.write(self.getDescription(test))
|
||||
self.stream.write(" ... ")
|
||||
self.stream.writeln(status)
|
||||
self._newline = True
|
||||
|
||||
def addSubTest(self, test, subtest, err):
|
||||
if err is not None:
|
||||
if self.showAll:
|
||||
if issubclass(err[0], subtest.failureException):
|
||||
self._write_status(subtest, "FAIL")
|
||||
else:
|
||||
self._write_status(subtest, "ERROR")
|
||||
elif self.dots:
|
||||
if issubclass(err[0], subtest.failureException):
|
||||
self.stream.write('F')
|
||||
else:
|
||||
self.stream.write('E')
|
||||
self.stream.flush()
|
||||
super(TextTestResult, self).addSubTest(test, subtest, err)
|
||||
|
||||
def addSuccess(self, test):
|
||||
super(TextTestResult, self).addSuccess(test)
|
||||
if self.showAll:
|
||||
self.stream.writeln("ok")
|
||||
self._write_status(test, "ok")
|
||||
elif self.dots:
|
||||
self.stream.write('.')
|
||||
self.stream.flush()
|
||||
|
|
@ -66,7 +96,7 @@ class TextTestResult(result.TestResult):
|
|||
def addError(self, test, err):
|
||||
super(TextTestResult, self).addError(test, err)
|
||||
if self.showAll:
|
||||
self.stream.writeln("ERROR")
|
||||
self._write_status(test, "ERROR")
|
||||
elif self.dots:
|
||||
self.stream.write('E')
|
||||
self.stream.flush()
|
||||
|
|
@ -74,7 +104,7 @@ class TextTestResult(result.TestResult):
|
|||
def addFailure(self, test, err):
|
||||
super(TextTestResult, self).addFailure(test, err)
|
||||
if self.showAll:
|
||||
self.stream.writeln("FAIL")
|
||||
self._write_status(test, "FAIL")
|
||||
elif self.dots:
|
||||
self.stream.write('F')
|
||||
self.stream.flush()
|
||||
|
|
@ -82,7 +112,7 @@ class TextTestResult(result.TestResult):
|
|||
def addSkip(self, test, reason):
|
||||
super(TextTestResult, self).addSkip(test, reason)
|
||||
if self.showAll:
|
||||
self.stream.writeln("skipped {0!r}".format(reason))
|
||||
self._write_status(test, "skipped {0!r}".format(reason))
|
||||
elif self.dots:
|
||||
self.stream.write("s")
|
||||
self.stream.flush()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue