""" Test Result -----------
Provides a TextTestResult that extends unittest's _TextTestResult to provide support for error classes (such as the builtin skip and deprecated classes), and hooks for plugins to take over or extend reporting. """
# 2.7+
# this is what stdlib module traceback does try: return str(exc) except: return '<unprintable %s object>' % type(exc).__name__
"""Text test result that extends unittest's default test result support for a configurable set of errorClasses (eg, Skip, Deprecated, TODO) that extend the errors/failures/success triad. """ errorClasses=None): config = Config()
# 2.7 skip compat from nose.plugins.skip import SkipTest if SkipTest in self.errorClasses: storage, label, isfail = self.errorClasses[SkipTest] storage.append((test, reason)) self.printLabel(label, (SkipTest, reason, None))
"""Overrides normal addError to add support for errorClasses. If the exception is a registered class, the error will be added to the list for that class, not errors. """ ec, ev, tb = err try: exc_info = self._exc_info_to_string(err, test) except TypeError: # 2.3 compat exc_info = self._exc_info_to_string(err) for cls, (storage, label, isfail) in list(self.errorClasses.items()): #if 'Skip' in cls.__name__ or 'Skip' in ec.__name__: # from nose.tools import set_trace # set_trace() if isclass(ec) and issubclass(ec, cls): if isfail: test.passed = False storage.append((test, exc_info)) self.printLabel(label, err) return self.errors.append((test, exc_info)) test.passed = False self.printLabel('ERROR')
# override to bypass changes in 2.7 else: return str(test)
# Might get patched into a streamless result stream = getattr(self, 'stream', None) if stream is not None: if self.showAll: message = [label] if err: detail = _exception_detail(err[1]) if detail: message.append(detail) stream.writeln(": ".join(message)) elif self.dots: stream.write(label[:1])
"""Overrides to print all errorClasses errors as well. """ self.printErrorList(label, storage) # Might get patched into a result with no config
"""Called by the test runner to print the final summary of test run results. """
summary[label] = count summary['failures'] = len(self.failures) summary['errors'] = len(self.errors)
write("FAILED") else: items.sort() write(" (") write(", ".join(["%s=%s" % (label, count) for label, count in items])) writeln(")") else:
"""Overrides to check that there are no errors in errorClasses lists that are marked as errors and should cause a run to fail. """ return False if storage: return False
try: exc_info = self._exc_info_to_string(err, test) except TypeError: # 2.3: does not take test arg exc_info = self._exc_info_to_string(err) self.errors.append((test, exc_info)) if self.showAll: self.stream.write('ERROR') elif self.dots: self.stream.write('E')
# 2.7 skip compat from nose.plugins.skip import SkipTest if isclass(err[0]) and issubclass(err[0], SkipTest): return str(err[1]) # 2.3/2.4 -- 2.4 passes test, 2.3 does not try: return _TextTestResult._exc_info_to_string(self, err, test) except TypeError: # 2.3: does not take test arg return _TextTestResult._exc_info_to_string(self, err)
from warnings import warn warn("ln() has moved to nose.util from nose.result and will be removed " "from nose.result in a future release. Please update your imports ", DeprecationWarning) return _ln(*arg, **kw)
|