Skip to content
Merged
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
33 changes: 2 additions & 31 deletions Lib/test/support/testresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
import unittest

class RegressionTestResult(unittest.TextTestResult):
separator1 = '=' * 70 + '\n'
separator2 = '-' * 70 + '\n'
USE_XML = False

def __init__(self, stream, descriptions, verbosity):
super().__init__(stream=stream, descriptions=descriptions, verbosity=0)
super().__init__(stream=stream, descriptions=descriptions,
verbosity=2 if verbosity else 0)
self.buffer = True
if self.USE_XML:
from xml.etree import ElementTree as ET
Expand All @@ -25,8 +24,6 @@ def __init__(self, stream, descriptions, verbosity):
self.__suite.set('start', datetime.utcnow().isoformat(' '))
self.__e = None
self.__start_time = None
self.__results = []
self.__verbose = bool(verbosity)

@classmethod
def __getId(cls, test):
Expand All @@ -45,9 +42,6 @@ def startTest(self, test):
if self.USE_XML:
self.__e = e = self.__ET.SubElement(self.__suite, 'testcase')
self.__start_time = time.perf_counter()
if self.__verbose:
self.stream.write(f'{self.getDescription(test)} ... ')
self.stream.flush()

def _add_result(self, test, capture=False, **args):
if not self.USE_XML:
Expand Down Expand Up @@ -85,10 +79,6 @@ def _add_result(self, test, capture=False, **args):
else:
e2.text = str(v)

def __write(self, c, word):
if self.__verbose:
self.stream.write(f'{word}\n')

@classmethod
def __makeErrorDict(cls, err_type, err_value, err_tb):
if isinstance(err_type, type):
Expand All @@ -111,45 +101,26 @@ def __makeErrorDict(cls, err_type, err_value, err_tb):
def addError(self, test, err):
self._add_result(test, True, error=self.__makeErrorDict(*err))
super().addError(test, err)
self.__write('E', 'ERROR')

def addExpectedFailure(self, test, err):
self._add_result(test, True, output=self.__makeErrorDict(*err))
super().addExpectedFailure(test, err)
self.__write('x', 'expected failure')

def addFailure(self, test, err):
self._add_result(test, True, failure=self.__makeErrorDict(*err))
super().addFailure(test, err)
self.__write('F', 'FAIL')

def addSkip(self, test, reason):
self._add_result(test, skipped=reason)
super().addSkip(test, reason)
self.__write('S', f'skipped {reason!r}')

def addSuccess(self, test):
self._add_result(test)
super().addSuccess(test)
self.__write('.', 'ok')

def addUnexpectedSuccess(self, test):
self._add_result(test, outcome='UNEXPECTED_SUCCESS')
super().addUnexpectedSuccess(test)
self.__write('u', 'unexpected success')

def printErrors(self):
if self.__verbose:
self.stream.write('\n')
self.printErrorList('ERROR', self.errors)
self.printErrorList('FAIL', self.failures)

def printErrorList(self, flavor, errors):
for test, err in errors:
self.stream.write(self.separator1)
self.stream.write(f'{flavor}: {self.getDescription(test)}\n')

@vstinner vstinner Aug 31, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can modernize printErrors() in Lib/unittest/runner.py. It contains very useless code like "%s" % err.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe in other PR. This PR does not touch that file.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you want, it was just a remark. I approved your PR (and you merged it ;-))

self.stream.write(self.separator2)
self.stream.write('%s\n' % err)

def get_xml_element(self):
if not self.USE_XML:
Expand Down