298
298
Called from the TestCase run() method when the test
299
299
fails with an unexpected error.
301
self._testConcluded(test)
302
if isinstance(err[1], TestNotApplicable):
303
return self._addNotApplicable(test, err)
304
elif isinstance(err[1], UnavailableFeature):
305
return self.addNotSupported(test, err[1].args[0])
308
unittest.TestResult.addError(self, test, err)
309
self.error_count += 1
310
self.report_error(test, err)
313
self._cleanupLogFile(test)
302
unittest.TestResult.addError(self, test, err)
303
self.error_count += 1
304
self.report_error(test, err)
307
self._cleanupLogFile(test)
315
309
def addFailure(self, test, err):
316
310
"""Tell result that test failed.
318
312
Called from the TestCase run() method when the test
319
313
fails because e.g. an assert() method failed.
321
self._testConcluded(test)
322
if isinstance(err[1], KnownFailure):
323
return self._addKnownFailure(test, err)
326
unittest.TestResult.addFailure(self, test, err)
327
self.failure_count += 1
328
self.report_failure(test, err)
331
self._cleanupLogFile(test)
316
unittest.TestResult.addFailure(self, test, err)
317
self.failure_count += 1
318
self.report_failure(test, err)
321
self._cleanupLogFile(test)
333
323
def addSuccess(self, test):
334
324
"""Tell result that test completed successfully.
336
326
Called from the TestCase run()
338
self._testConcluded(test)
339
328
if self._bench_history is not None:
340
329
benchmark_time = self._extractBenchmarkTime(test)
341
330
if benchmark_time is not None:
376
358
self.skip_count += 1
377
359
self.report_skip(test, reason)
379
def _addNotApplicable(self, test, skip_excinfo):
380
if isinstance(skip_excinfo[1], TestNotApplicable):
381
self.not_applicable_count += 1
382
self.report_not_applicable(test, skip_excinfo)
385
except KeyboardInterrupt:
388
self.addError(test, test.exc_info())
390
# seems best to treat this as success from point-of-view of unittest
391
# -- it actually does nothing so it barely matters :)
392
unittest.TestResult.addSuccess(self, test)
393
test._log_contents = ''
361
def addNotApplicable(self, test, reason):
362
self.not_applicable_count += 1
363
self.report_not_applicable(test, reason)
395
365
def printErrorList(self, flavour, errors):
396
366
for test, err in errors:
1595
1566
def _do_skip(self, result, reason):
1596
1567
addSkip = getattr(result, 'addSkip', None)
1597
1568
if not callable(addSkip):
1598
result.addError(self, sys.exc_info())
1569
result.addSuccess(result)
1600
1571
addSkip(self, reason)
1573
def _do_known_failure(self, result):
1574
err = sys.exc_info()
1575
addExpectedFailure = getattr(result, 'addExpectedFailure', None)
1576
if addExpectedFailure is not None:
1577
addExpectedFailure(self, err)
1579
result.addSuccess(self)
1581
def _do_not_applicable(self, result, e):
1583
reason = 'No reason given'
1586
addNotApplicable = getattr(result, 'addNotApplicable', None)
1587
if addNotApplicable is not None:
1588
result.addNotApplicable(self, reason)
1590
self._do_skip(result, reason)
1592
def _do_unsupported_or_skip(self, result, reason):
1593
addNotSupported = getattr(result, 'addNotSupported', None)
1594
if addNotSupported is not None:
1595
result.addNotSupported(self, reason)
1597
self._do_skip(result, reason)
1602
1599
def run(self, result=None):
1603
1600
if result is None: result = self.defaultTestResult()
1601
result.startTest(self)
1606
result.stopTest(self)
1608
def _run(self, result):
1604
1609
for feature in getattr(self, '_test_needs_features', []):
1605
1610
if not feature.available():
1606
result.startTest(self)
1607
if getattr(result, 'addNotSupported', None):
1608
result.addNotSupported(self, feature)
1610
result.addSuccess(self)
1611
result.stopTest(self)
1611
return self._do_unsupported_or_skip(result, feature)
1613
absent_attr = object()
1615
method_name = getattr(self, '_testMethodName', absent_attr)
1616
if method_name is absent_attr:
1618
method_name = getattr(self, '_TestCase__testMethodName')
1619
testMethod = getattr(self, method_name)
1615
result.startTest(self)
1616
absent_attr = object()
1618
method_name = getattr(self, '_testMethodName', absent_attr)
1619
if method_name is absent_attr:
1621
method_name = getattr(self, '_TestCase__testMethodName')
1622
testMethod = getattr(self, method_name)
1626
if not self._bzr_test_setUp_run:
1628
"test setUp did not invoke "
1629
"bzrlib.tests.TestCase's setUp")
1630
except KeyboardInterrupt:
1633
except TestSkipped, e:
1634
self._do_skip(result, e.args[0])
1638
result.addError(self, sys.exc_info())
1623
if not self._bzr_test_setUp_run:
1625
"test setUp did not invoke "
1626
"bzrlib.tests.TestCase's setUp")
1627
except KeyboardInterrupt:
1630
except KnownFailure:
1631
self._do_known_failure(result)
1634
except TestNotApplicable, e:
1635
self._do_not_applicable(result, e)
1638
except TestSkipped, e:
1639
self._do_skip(result, e.args[0])
1642
except UnavailableFeature, e:
1643
self._do_unsupported_or_skip(result, e.args[0])
1647
result.addError(self, sys.exc_info())
1655
except KnownFailure:
1656
self._do_known_failure(result)
1657
except self.failureException:
1658
result.addFailure(self, sys.exc_info())
1659
except TestNotApplicable, e:
1660
self._do_not_applicable(result, e)
1661
except TestSkipped, e:
1663
reason = "No reason given."
1666
self._do_skip(result, reason)
1667
except UnavailableFeature, e:
1668
self._do_unsupported_or_skip(result, e.args[0])
1669
except KeyboardInterrupt:
1673
result.addError(self, sys.exc_info())
1677
if not self._bzr_test_tearDown_run:
1679
"test tearDown did not invoke "
1680
"bzrlib.tests.TestCase's tearDown")
1681
except KeyboardInterrupt:
1685
result.addError(self, sys.exc_info())
1646
except self.failureException:
1647
result.addFailure(self, sys.exc_info())
1648
except TestSkipped, e:
1650
reason = "No reason given."
1653
self._do_skip(result, reason)
1654
except KeyboardInterrupt:
1658
result.addError(self, sys.exc_info())
1662
if not self._bzr_test_tearDown_run:
1664
"test tearDown did not invoke "
1665
"bzrlib.tests.TestCase's tearDown")
1666
except KeyboardInterrupt:
1670
result.addError(self, sys.exc_info())
1673
if ok: result.addSuccess(self)
1675
result.stopTest(self)
1688
if ok: result.addSuccess(self)
1677
except TestNotApplicable:
1678
# Not moved from the result [yet].
1681
1690
except KeyboardInterrupt:
1682
1691
self._runCleanups()