2009-07-20 05:01:52 +08:00
|
|
|
"""Running tests"""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import time
|
2010-12-01 08:56:10 +08:00
|
|
|
import warnings
|
2009-07-20 05:01:52 +08:00
|
|
|
|
|
|
|
from . import result
|
2021-09-10 23:55:05 +08:00
|
|
|
from .case import _SubTest
|
2010-03-27 21:25:41 +08:00
|
|
|
from .signals import registerResult
|
2009-07-20 05:01:52 +08:00
|
|
|
|
2010-03-22 08:15:53 +08:00
|
|
|
__unittest = True
|
|
|
|
|
2009-07-20 05:01:52 +08:00
|
|
|
|
|
|
|
class _WritelnDecorator(object):
|
|
|
|
"""Used to decorate file-like objects with a handy 'writeln' method"""
|
|
|
|
def __init__(self,stream):
|
|
|
|
self.stream = stream
|
|
|
|
|
|
|
|
def __getattr__(self, attr):
|
2009-11-11 05:34:48 +08:00
|
|
|
if attr in ('stream', '__getstate__'):
|
|
|
|
raise AttributeError(attr)
|
2009-07-20 05:01:52 +08:00
|
|
|
return getattr(self.stream,attr)
|
|
|
|
|
|
|
|
def writeln(self, arg=None):
|
|
|
|
if arg:
|
|
|
|
self.write(arg)
|
|
|
|
self.write('\n') # text-mode streams translate to \r\n if needed
|
|
|
|
|
|
|
|
|
2010-02-10 23:51:42 +08:00
|
|
|
class TextTestResult(result.TestResult):
|
2009-07-20 05:01:52 +08:00
|
|
|
"""A test result class that can print formatted text results to a stream.
|
|
|
|
|
|
|
|
Used by TextTestRunner.
|
|
|
|
"""
|
|
|
|
separator1 = '=' * 70
|
|
|
|
separator2 = '-' * 70
|
|
|
|
|
2023-04-03 06:12:51 +08:00
|
|
|
def __init__(self, stream, descriptions, verbosity, *, durations=None):
|
|
|
|
"""Construct a TextTestResult. Subclasses should accept **kwargs
|
|
|
|
to ensure compatibility as the interface changes."""
|
2012-09-28 21:14:03 +08:00
|
|
|
super(TextTestResult, self).__init__(stream, descriptions, verbosity)
|
2009-07-20 05:01:52 +08:00
|
|
|
self.stream = stream
|
|
|
|
self.showAll = verbosity > 1
|
|
|
|
self.dots = verbosity == 1
|
|
|
|
self.descriptions = descriptions
|
2021-09-10 23:55:05 +08:00
|
|
|
self._newline = True
|
2023-04-03 06:12:51 +08:00
|
|
|
self.durations = durations
|
2009-07-20 05:01:52 +08:00
|
|
|
|
|
|
|
def getDescription(self, test):
|
2010-02-10 23:51:42 +08:00
|
|
|
doc_first_line = test.shortDescription()
|
|
|
|
if self.descriptions and doc_first_line:
|
|
|
|
return '\n'.join((str(test), doc_first_line))
|
2009-07-20 05:01:52 +08:00
|
|
|
else:
|
|
|
|
return str(test)
|
|
|
|
|
|
|
|
def startTest(self, test):
|
2010-02-10 23:51:42 +08:00
|
|
|
super(TextTestResult, self).startTest(test)
|
2009-07-20 05:01:52 +08:00
|
|
|
if self.showAll:
|
|
|
|
self.stream.write(self.getDescription(test))
|
|
|
|
self.stream.write(" ... ")
|
|
|
|
self.stream.flush()
|
2021-09-10 23:55:05 +08:00
|
|
|
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)
|
2021-12-05 02:57:20 +08:00
|
|
|
self.stream.flush()
|
2021-09-10 23:55:05 +08:00
|
|
|
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)
|
2009-07-20 05:01:52 +08:00
|
|
|
|
|
|
|
def addSuccess(self, test):
|
2010-02-10 23:51:42 +08:00
|
|
|
super(TextTestResult, self).addSuccess(test)
|
2009-07-20 05:01:52 +08:00
|
|
|
if self.showAll:
|
2021-09-10 23:55:05 +08:00
|
|
|
self._write_status(test, "ok")
|
2009-07-20 05:01:52 +08:00
|
|
|
elif self.dots:
|
|
|
|
self.stream.write('.')
|
|
|
|
self.stream.flush()
|
|
|
|
|
|
|
|
def addError(self, test, err):
|
2010-02-10 23:51:42 +08:00
|
|
|
super(TextTestResult, self).addError(test, err)
|
2009-07-20 05:01:52 +08:00
|
|
|
if self.showAll:
|
2021-09-10 23:55:05 +08:00
|
|
|
self._write_status(test, "ERROR")
|
2009-07-20 05:01:52 +08:00
|
|
|
elif self.dots:
|
|
|
|
self.stream.write('E')
|
|
|
|
self.stream.flush()
|
|
|
|
|
|
|
|
def addFailure(self, test, err):
|
2010-02-10 23:51:42 +08:00
|
|
|
super(TextTestResult, self).addFailure(test, err)
|
2009-07-20 05:01:52 +08:00
|
|
|
if self.showAll:
|
2021-09-10 23:55:05 +08:00
|
|
|
self._write_status(test, "FAIL")
|
2009-07-20 05:01:52 +08:00
|
|
|
elif self.dots:
|
|
|
|
self.stream.write('F')
|
|
|
|
self.stream.flush()
|
|
|
|
|
|
|
|
def addSkip(self, test, reason):
|
2010-02-10 23:51:42 +08:00
|
|
|
super(TextTestResult, self).addSkip(test, reason)
|
2009-07-20 05:01:52 +08:00
|
|
|
if self.showAll:
|
2021-09-10 23:55:05 +08:00
|
|
|
self._write_status(test, "skipped {0!r}".format(reason))
|
2009-07-20 05:01:52 +08:00
|
|
|
elif self.dots:
|
|
|
|
self.stream.write("s")
|
|
|
|
self.stream.flush()
|
|
|
|
|
|
|
|
def addExpectedFailure(self, test, err):
|
2010-02-10 23:51:42 +08:00
|
|
|
super(TextTestResult, self).addExpectedFailure(test, err)
|
2009-07-20 05:01:52 +08:00
|
|
|
if self.showAll:
|
|
|
|
self.stream.writeln("expected failure")
|
2021-12-05 02:57:20 +08:00
|
|
|
self.stream.flush()
|
2009-07-20 05:01:52 +08:00
|
|
|
elif self.dots:
|
|
|
|
self.stream.write("x")
|
|
|
|
self.stream.flush()
|
|
|
|
|
|
|
|
def addUnexpectedSuccess(self, test):
|
2010-02-10 23:51:42 +08:00
|
|
|
super(TextTestResult, self).addUnexpectedSuccess(test)
|
2009-07-20 05:01:52 +08:00
|
|
|
if self.showAll:
|
|
|
|
self.stream.writeln("unexpected success")
|
2021-12-05 02:57:20 +08:00
|
|
|
self.stream.flush()
|
2009-07-20 05:01:52 +08:00
|
|
|
elif self.dots:
|
|
|
|
self.stream.write("u")
|
|
|
|
self.stream.flush()
|
|
|
|
|
|
|
|
def printErrors(self):
|
|
|
|
if self.dots or self.showAll:
|
|
|
|
self.stream.writeln()
|
2021-12-05 02:57:20 +08:00
|
|
|
self.stream.flush()
|
2009-07-20 05:01:52 +08:00
|
|
|
self.printErrorList('ERROR', self.errors)
|
|
|
|
self.printErrorList('FAIL', self.failures)
|
2021-12-26 19:22:44 +08:00
|
|
|
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()
|
2009-07-20 05:01:52 +08:00
|
|
|
|
|
|
|
def printErrorList(self, flavour, errors):
|
|
|
|
for test, err in errors:
|
|
|
|
self.stream.writeln(self.separator1)
|
|
|
|
self.stream.writeln("%s: %s" % (flavour,self.getDescription(test)))
|
|
|
|
self.stream.writeln(self.separator2)
|
|
|
|
self.stream.writeln("%s" % err)
|
2021-12-05 02:57:20 +08:00
|
|
|
self.stream.flush()
|
2009-07-20 05:01:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
class TextTestRunner(object):
|
|
|
|
"""A test runner class that displays results in textual form.
|
|
|
|
|
|
|
|
It prints out the names of tests as they are run, errors as they
|
|
|
|
occur, and a summary of the results at the end of the test run.
|
|
|
|
"""
|
2010-02-10 23:51:42 +08:00
|
|
|
resultclass = TextTestResult
|
|
|
|
|
2010-12-31 03:36:29 +08:00
|
|
|
def __init__(self, stream=None, descriptions=True, verbosity=1,
|
2015-03-06 08:46:35 +08:00
|
|
|
failfast=False, buffer=False, resultclass=None, warnings=None,
|
2023-04-03 06:12:51 +08:00
|
|
|
*, tb_locals=False, durations=None):
|
2015-03-06 08:46:35 +08:00
|
|
|
"""Construct a TextTestRunner.
|
|
|
|
|
|
|
|
Subclasses should accept **kwargs to ensure compatibility as the
|
|
|
|
interface changes.
|
|
|
|
"""
|
2010-12-31 03:36:29 +08:00
|
|
|
if stream is None:
|
|
|
|
stream = sys.stderr
|
2009-07-20 05:01:52 +08:00
|
|
|
self.stream = _WritelnDecorator(stream)
|
|
|
|
self.descriptions = descriptions
|
|
|
|
self.verbosity = verbosity
|
2010-03-22 09:13:48 +08:00
|
|
|
self.failfast = failfast
|
Merged revisions 79464,79471,79623,79626,79630,79632,79643,79648-79649,79679,79685,79711,79761,79774,79777,79792-79794,79877,79898-79900 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r79464 | michael.foord | 2010-03-27 07:55:19 -0500 (Sat, 27 Mar 2010) | 1 line
A fix for running unittest tests on platforms without the audioop module (e.g. jython and IronPython)
........
r79471 | michael.foord | 2010-03-27 14:10:11 -0500 (Sat, 27 Mar 2010) | 4 lines
Addition of delta keyword argument to unittest.TestCase.assertAlmostEquals and assertNotAlmostEquals
This allows the comparison of objects by specifying a maximum difference; this includes the comparing of non-numeric objects that don't support rounding.
........
r79623 | michael.foord | 2010-04-02 16:42:47 -0500 (Fri, 02 Apr 2010) | 1 line
Addition of -b command line option to unittest for buffering stdout and stderr during test runs.
........
r79626 | michael.foord | 2010-04-02 17:08:29 -0500 (Fri, 02 Apr 2010) | 1 line
TestResult stores original sys.stdout and tests no longer use sys.__stdout__ (etc) in tests for unittest -b command line option
........
r79630 | michael.foord | 2010-04-02 17:30:56 -0500 (Fri, 02 Apr 2010) | 1 line
unittest tests no longer replace the sys.stdout put in place by regrtest
........
r79632 | michael.foord | 2010-04-02 17:55:59 -0500 (Fri, 02 Apr 2010) | 1 line
Issue #8038: Addition of unittest.TestCase.assertNotRegexpMatches
........
r79643 | michael.foord | 2010-04-02 20:15:21 -0500 (Fri, 02 Apr 2010) | 1 line
Support dotted module names for test discovery paths in unittest. Issue 8038.
........
r79648 | michael.foord | 2010-04-02 21:21:39 -0500 (Fri, 02 Apr 2010) | 1 line
Cross platform unittest.TestResult newline handling when buffering stdout / stderr.
........
r79649 | michael.foord | 2010-04-02 21:33:55 -0500 (Fri, 02 Apr 2010) | 1 line
Another attempt at a fix for unittest.test.test_result for windows line endings
........
r79679 | michael.foord | 2010-04-03 09:52:18 -0500 (Sat, 03 Apr 2010) | 1 line
Adding -b command line option to the unittest usage message.
........
r79685 | michael.foord | 2010-04-03 10:20:00 -0500 (Sat, 03 Apr 2010) | 1 line
Minor tweak to unittest command line usage message
........
r79711 | michael.foord | 2010-04-03 12:03:11 -0500 (Sat, 03 Apr 2010) | 1 line
Documenting new features in unittest
........
r79761 | michael.foord | 2010-04-04 17:41:54 -0500 (Sun, 04 Apr 2010) | 1 line
unittest documentation formatting changes
........
r79774 | michael.foord | 2010-04-04 18:28:44 -0500 (Sun, 04 Apr 2010) | 1 line
Adding documentation for new unittest.main() parameters
........
r79777 | michael.foord | 2010-04-04 19:39:50 -0500 (Sun, 04 Apr 2010) | 1 line
Document signal handling functions in unittest.rst
........
r79792 | michael.foord | 2010-04-05 05:26:26 -0500 (Mon, 05 Apr 2010) | 1 line
Documentation fixes for unittest
........
r79793 | michael.foord | 2010-04-05 05:28:27 -0500 (Mon, 05 Apr 2010) | 1 line
Furterh documentation fix for unittest.rst
........
r79794 | michael.foord | 2010-04-05 05:30:14 -0500 (Mon, 05 Apr 2010) | 1 line
Further documentation fix for unittest.rst
........
r79877 | michael.foord | 2010-04-06 18:18:16 -0500 (Tue, 06 Apr 2010) | 1 line
Fix module directory finding logic for dotted paths in unittest test discovery.
........
r79898 | michael.foord | 2010-04-07 18:04:22 -0500 (Wed, 07 Apr 2010) | 1 line
unittest.result.TestResult does not create its buffers until they're used. It uses StringIO not cStringIO. Issue 8333.
........
r79899 | michael.foord | 2010-04-07 19:04:24 -0500 (Wed, 07 Apr 2010) | 1 line
Switch regrtest to use StringIO instead of cStringIO for test_multiprocessing on Windows. Issue 8333.
........
r79900 | michael.foord | 2010-04-07 23:33:20 -0500 (Wed, 07 Apr 2010) | 1 line
Correction of unittest documentation typos and omissions
........
2010-04-12 04:43:16 +08:00
|
|
|
self.buffer = buffer
|
2015-03-06 08:46:35 +08:00
|
|
|
self.tb_locals = tb_locals
|
2023-04-03 06:12:51 +08:00
|
|
|
self.durations = durations
|
2010-12-01 08:56:10 +08:00
|
|
|
self.warnings = warnings
|
2010-02-10 23:51:42 +08:00
|
|
|
if resultclass is not None:
|
|
|
|
self.resultclass = resultclass
|
2009-07-20 05:01:52 +08:00
|
|
|
|
|
|
|
def _makeResult(self):
|
2023-04-03 06:12:51 +08:00
|
|
|
try:
|
|
|
|
return self.resultclass(self.stream, self.descriptions,
|
|
|
|
self.verbosity, durations=self.durations)
|
|
|
|
except TypeError:
|
|
|
|
# didn't accept the durations argument
|
|
|
|
return self.resultclass(self.stream, self.descriptions,
|
|
|
|
self.verbosity)
|
|
|
|
|
|
|
|
def _printDurations(self, result):
|
|
|
|
if not result.collectedDurations:
|
|
|
|
return
|
|
|
|
ls = sorted(result.collectedDurations, key=lambda x: x[1],
|
|
|
|
reverse=True)
|
|
|
|
if self.durations > 0:
|
|
|
|
ls = ls[:self.durations]
|
|
|
|
self.stream.writeln("Slowest test durations")
|
|
|
|
if hasattr(result, 'separator2'):
|
|
|
|
self.stream.writeln(result.separator2)
|
|
|
|
hidden = False
|
|
|
|
for test, elapsed in ls:
|
|
|
|
if self.verbosity < 2 and elapsed < 0.001:
|
|
|
|
hidden = True
|
|
|
|
continue
|
|
|
|
self.stream.writeln("%-10s %s" % ("%.3fs" % elapsed, test))
|
|
|
|
if hidden:
|
|
|
|
self.stream.writeln("\n(durations < 0.001s were hidden; "
|
|
|
|
"use -v to show these durations)")
|
|
|
|
else:
|
|
|
|
self.stream.writeln("")
|
2009-07-20 05:01:52 +08:00
|
|
|
|
|
|
|
def run(self, test):
|
|
|
|
"Run the given test case or test suite."
|
|
|
|
result = self._makeResult()
|
2010-03-27 21:25:41 +08:00
|
|
|
registerResult(result)
|
2010-03-22 09:13:48 +08:00
|
|
|
result.failfast = self.failfast
|
Merged revisions 79464,79471,79623,79626,79630,79632,79643,79648-79649,79679,79685,79711,79761,79774,79777,79792-79794,79877,79898-79900 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r79464 | michael.foord | 2010-03-27 07:55:19 -0500 (Sat, 27 Mar 2010) | 1 line
A fix for running unittest tests on platforms without the audioop module (e.g. jython and IronPython)
........
r79471 | michael.foord | 2010-03-27 14:10:11 -0500 (Sat, 27 Mar 2010) | 4 lines
Addition of delta keyword argument to unittest.TestCase.assertAlmostEquals and assertNotAlmostEquals
This allows the comparison of objects by specifying a maximum difference; this includes the comparing of non-numeric objects that don't support rounding.
........
r79623 | michael.foord | 2010-04-02 16:42:47 -0500 (Fri, 02 Apr 2010) | 1 line
Addition of -b command line option to unittest for buffering stdout and stderr during test runs.
........
r79626 | michael.foord | 2010-04-02 17:08:29 -0500 (Fri, 02 Apr 2010) | 1 line
TestResult stores original sys.stdout and tests no longer use sys.__stdout__ (etc) in tests for unittest -b command line option
........
r79630 | michael.foord | 2010-04-02 17:30:56 -0500 (Fri, 02 Apr 2010) | 1 line
unittest tests no longer replace the sys.stdout put in place by regrtest
........
r79632 | michael.foord | 2010-04-02 17:55:59 -0500 (Fri, 02 Apr 2010) | 1 line
Issue #8038: Addition of unittest.TestCase.assertNotRegexpMatches
........
r79643 | michael.foord | 2010-04-02 20:15:21 -0500 (Fri, 02 Apr 2010) | 1 line
Support dotted module names for test discovery paths in unittest. Issue 8038.
........
r79648 | michael.foord | 2010-04-02 21:21:39 -0500 (Fri, 02 Apr 2010) | 1 line
Cross platform unittest.TestResult newline handling when buffering stdout / stderr.
........
r79649 | michael.foord | 2010-04-02 21:33:55 -0500 (Fri, 02 Apr 2010) | 1 line
Another attempt at a fix for unittest.test.test_result for windows line endings
........
r79679 | michael.foord | 2010-04-03 09:52:18 -0500 (Sat, 03 Apr 2010) | 1 line
Adding -b command line option to the unittest usage message.
........
r79685 | michael.foord | 2010-04-03 10:20:00 -0500 (Sat, 03 Apr 2010) | 1 line
Minor tweak to unittest command line usage message
........
r79711 | michael.foord | 2010-04-03 12:03:11 -0500 (Sat, 03 Apr 2010) | 1 line
Documenting new features in unittest
........
r79761 | michael.foord | 2010-04-04 17:41:54 -0500 (Sun, 04 Apr 2010) | 1 line
unittest documentation formatting changes
........
r79774 | michael.foord | 2010-04-04 18:28:44 -0500 (Sun, 04 Apr 2010) | 1 line
Adding documentation for new unittest.main() parameters
........
r79777 | michael.foord | 2010-04-04 19:39:50 -0500 (Sun, 04 Apr 2010) | 1 line
Document signal handling functions in unittest.rst
........
r79792 | michael.foord | 2010-04-05 05:26:26 -0500 (Mon, 05 Apr 2010) | 1 line
Documentation fixes for unittest
........
r79793 | michael.foord | 2010-04-05 05:28:27 -0500 (Mon, 05 Apr 2010) | 1 line
Furterh documentation fix for unittest.rst
........
r79794 | michael.foord | 2010-04-05 05:30:14 -0500 (Mon, 05 Apr 2010) | 1 line
Further documentation fix for unittest.rst
........
r79877 | michael.foord | 2010-04-06 18:18:16 -0500 (Tue, 06 Apr 2010) | 1 line
Fix module directory finding logic for dotted paths in unittest test discovery.
........
r79898 | michael.foord | 2010-04-07 18:04:22 -0500 (Wed, 07 Apr 2010) | 1 line
unittest.result.TestResult does not create its buffers until they're used. It uses StringIO not cStringIO. Issue 8333.
........
r79899 | michael.foord | 2010-04-07 19:04:24 -0500 (Wed, 07 Apr 2010) | 1 line
Switch regrtest to use StringIO instead of cStringIO for test_multiprocessing on Windows. Issue 8333.
........
r79900 | michael.foord | 2010-04-07 23:33:20 -0500 (Wed, 07 Apr 2010) | 1 line
Correction of unittest documentation typos and omissions
........
2010-04-12 04:43:16 +08:00
|
|
|
result.buffer = self.buffer
|
2015-03-06 08:46:35 +08:00
|
|
|
result.tb_locals = self.tb_locals
|
2010-12-01 08:56:10 +08:00
|
|
|
with warnings.catch_warnings():
|
|
|
|
if self.warnings:
|
|
|
|
# if self.warnings is set, use it to filter all the warnings
|
|
|
|
warnings.simplefilter(self.warnings)
|
2018-12-17 18:30:34 +08:00
|
|
|
startTime = time.perf_counter()
|
2010-12-01 08:56:10 +08:00
|
|
|
startTestRun = getattr(result, 'startTestRun', None)
|
|
|
|
if startTestRun is not None:
|
|
|
|
startTestRun()
|
|
|
|
try:
|
|
|
|
test(result)
|
|
|
|
finally:
|
|
|
|
stopTestRun = getattr(result, 'stopTestRun', None)
|
|
|
|
if stopTestRun is not None:
|
|
|
|
stopTestRun()
|
2018-12-17 18:30:34 +08:00
|
|
|
stopTime = time.perf_counter()
|
2009-07-20 05:01:52 +08:00
|
|
|
timeTaken = stopTime - startTime
|
|
|
|
result.printErrors()
|
2023-04-03 06:12:51 +08:00
|
|
|
if self.durations is not None:
|
|
|
|
self._printDurations(result)
|
|
|
|
|
Merged revisions 78227,78229,78288,78348,78377,78770,78774-78776,78810 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78227 | michael.foord | 2010-02-18 14:30:09 -0600 (Thu, 18 Feb 2010) | 1 line
unittest.TestCase uses safe_repr for producing failure messages. Partial fix for issue 7956
........
r78229 | michael.foord | 2010-02-18 15:37:07 -0600 (Thu, 18 Feb 2010) | 1 line
Fix unittest.TestCase.assertDictContainsSubset so it can't die with unicode issues when constructing failure messages. Issue 7956
........
r78288 | michael.foord | 2010-02-21 08:48:59 -0600 (Sun, 21 Feb 2010) | 1 line
Silence UnicodeWarning in crazy unittest test.
........
r78348 | michael.foord | 2010-02-22 17:28:32 -0600 (Mon, 22 Feb 2010) | 1 line
Support for old TestResult object (unittest) with warnings when using unsupported features.
........
r78377 | michael.foord | 2010-02-23 11:00:53 -0600 (Tue, 23 Feb 2010) | 1 line
unittest.TestResult can now be used with the TextTestRunner. TextTestRunner compatible with old TestResult objects.
........
r78770 | michael.foord | 2010-03-07 14:22:12 -0600 (Sun, 07 Mar 2010) | 1 line
Fix for potentials errors in constructing unittest failure messages. Plus skipped test methods no longer run setUp and tearDown (Issue 8059)
........
r78774 | michael.foord | 2010-03-07 16:04:55 -0600 (Sun, 07 Mar 2010) | 1 line
Addition of setUpClass and setUpModule shared fixtures to unittest.
........
r78775 | michael.foord | 2010-03-07 17:10:36 -0600 (Sun, 07 Mar 2010) | 1 line
Fix accidental name rebinding in unittest py3k warning filtering.
........
r78776 | michael.foord | 2010-03-07 17:16:20 -0600 (Sun, 07 Mar 2010) | 1 line
Remove accidental print statement from last commit.
........
r78810 | raymond.hettinger | 2010-03-09 02:44:18 -0600 (Tue, 09 Mar 2010) | 5 lines
Improve the basic example.
* Show both the decorator and regular form for assertRaises()
* Use assertTrue() instead of assertIn() to teach useful minimal subset of the API
........
2010-03-14 23:04:17 +08:00
|
|
|
if hasattr(result, 'separator2'):
|
|
|
|
self.stream.writeln(result.separator2)
|
2023-04-03 06:12:51 +08:00
|
|
|
|
2009-07-20 05:01:52 +08:00
|
|
|
run = result.testsRun
|
|
|
|
self.stream.writeln("Ran %d test%s in %.3fs" %
|
|
|
|
(run, run != 1 and "s" or "", timeTaken))
|
|
|
|
self.stream.writeln()
|
Merged revisions 78227,78229,78288,78348,78377,78770,78774-78776,78810 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78227 | michael.foord | 2010-02-18 14:30:09 -0600 (Thu, 18 Feb 2010) | 1 line
unittest.TestCase uses safe_repr for producing failure messages. Partial fix for issue 7956
........
r78229 | michael.foord | 2010-02-18 15:37:07 -0600 (Thu, 18 Feb 2010) | 1 line
Fix unittest.TestCase.assertDictContainsSubset so it can't die with unicode issues when constructing failure messages. Issue 7956
........
r78288 | michael.foord | 2010-02-21 08:48:59 -0600 (Sun, 21 Feb 2010) | 1 line
Silence UnicodeWarning in crazy unittest test.
........
r78348 | michael.foord | 2010-02-22 17:28:32 -0600 (Mon, 22 Feb 2010) | 1 line
Support for old TestResult object (unittest) with warnings when using unsupported features.
........
r78377 | michael.foord | 2010-02-23 11:00:53 -0600 (Tue, 23 Feb 2010) | 1 line
unittest.TestResult can now be used with the TextTestRunner. TextTestRunner compatible with old TestResult objects.
........
r78770 | michael.foord | 2010-03-07 14:22:12 -0600 (Sun, 07 Mar 2010) | 1 line
Fix for potentials errors in constructing unittest failure messages. Plus skipped test methods no longer run setUp and tearDown (Issue 8059)
........
r78774 | michael.foord | 2010-03-07 16:04:55 -0600 (Sun, 07 Mar 2010) | 1 line
Addition of setUpClass and setUpModule shared fixtures to unittest.
........
r78775 | michael.foord | 2010-03-07 17:10:36 -0600 (Sun, 07 Mar 2010) | 1 line
Fix accidental name rebinding in unittest py3k warning filtering.
........
r78776 | michael.foord | 2010-03-07 17:16:20 -0600 (Sun, 07 Mar 2010) | 1 line
Remove accidental print statement from last commit.
........
r78810 | raymond.hettinger | 2010-03-09 02:44:18 -0600 (Tue, 09 Mar 2010) | 5 lines
Improve the basic example.
* Show both the decorator and regular form for assertRaises()
* Use assertTrue() instead of assertIn() to teach useful minimal subset of the API
........
2010-03-14 23:04:17 +08:00
|
|
|
|
|
|
|
expectedFails = unexpectedSuccesses = skipped = 0
|
|
|
|
try:
|
|
|
|
results = map(len, (result.expectedFailures,
|
|
|
|
result.unexpectedSuccesses,
|
|
|
|
result.skipped))
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
2010-11-18 22:14:43 +08:00
|
|
|
else:
|
|
|
|
expectedFails, unexpectedSuccesses, skipped = results
|
Merged revisions 78227,78229,78288,78348,78377,78770,78774-78776,78810 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78227 | michael.foord | 2010-02-18 14:30:09 -0600 (Thu, 18 Feb 2010) | 1 line
unittest.TestCase uses safe_repr for producing failure messages. Partial fix for issue 7956
........
r78229 | michael.foord | 2010-02-18 15:37:07 -0600 (Thu, 18 Feb 2010) | 1 line
Fix unittest.TestCase.assertDictContainsSubset so it can't die with unicode issues when constructing failure messages. Issue 7956
........
r78288 | michael.foord | 2010-02-21 08:48:59 -0600 (Sun, 21 Feb 2010) | 1 line
Silence UnicodeWarning in crazy unittest test.
........
r78348 | michael.foord | 2010-02-22 17:28:32 -0600 (Mon, 22 Feb 2010) | 1 line
Support for old TestResult object (unittest) with warnings when using unsupported features.
........
r78377 | michael.foord | 2010-02-23 11:00:53 -0600 (Tue, 23 Feb 2010) | 1 line
unittest.TestResult can now be used with the TextTestRunner. TextTestRunner compatible with old TestResult objects.
........
r78770 | michael.foord | 2010-03-07 14:22:12 -0600 (Sun, 07 Mar 2010) | 1 line
Fix for potentials errors in constructing unittest failure messages. Plus skipped test methods no longer run setUp and tearDown (Issue 8059)
........
r78774 | michael.foord | 2010-03-07 16:04:55 -0600 (Sun, 07 Mar 2010) | 1 line
Addition of setUpClass and setUpModule shared fixtures to unittest.
........
r78775 | michael.foord | 2010-03-07 17:10:36 -0600 (Sun, 07 Mar 2010) | 1 line
Fix accidental name rebinding in unittest py3k warning filtering.
........
r78776 | michael.foord | 2010-03-07 17:16:20 -0600 (Sun, 07 Mar 2010) | 1 line
Remove accidental print statement from last commit.
........
r78810 | raymond.hettinger | 2010-03-09 02:44:18 -0600 (Tue, 09 Mar 2010) | 5 lines
Improve the basic example.
* Show both the decorator and regular form for assertRaises()
* Use assertTrue() instead of assertIn() to teach useful minimal subset of the API
........
2010-03-14 23:04:17 +08:00
|
|
|
|
2009-07-20 05:01:52 +08:00
|
|
|
infos = []
|
|
|
|
if not result.wasSuccessful():
|
|
|
|
self.stream.write("FAILED")
|
|
|
|
failed, errored = len(result.failures), len(result.errors)
|
|
|
|
if failed:
|
|
|
|
infos.append("failures=%d" % failed)
|
|
|
|
if errored:
|
|
|
|
infos.append("errors=%d" % errored)
|
2023-04-27 09:28:46 +08:00
|
|
|
elif run == 0:
|
|
|
|
self.stream.write("NO TESTS RAN")
|
2009-07-20 05:01:52 +08:00
|
|
|
else:
|
|
|
|
self.stream.write("OK")
|
|
|
|
if skipped:
|
|
|
|
infos.append("skipped=%d" % skipped)
|
|
|
|
if expectedFails:
|
|
|
|
infos.append("expected failures=%d" % expectedFails)
|
|
|
|
if unexpectedSuccesses:
|
|
|
|
infos.append("unexpected successes=%d" % unexpectedSuccesses)
|
|
|
|
if infos:
|
|
|
|
self.stream.writeln(" (%s)" % (", ".join(infos),))
|
|
|
|
else:
|
|
|
|
self.stream.write("\n")
|
2021-12-05 02:57:20 +08:00
|
|
|
self.stream.flush()
|
2009-07-20 05:01:52 +08:00
|
|
|
return result
|