nose-devs/nose — Issue #408: Factor out errorClass support
Author: jpellerin
Created: 2011-12-14 16:10:23+00:00
State: open

It would be great if the default errorClass handling from nose.result.TextTestResult.addError() were factored out for use by custom test result classes. In my nose-progressive plugin, for example, I need to override addError in order to do custom reporting (and suppress the dots), and so I must either duplicate about 10 lines of errorClass-handling code or else call the original addError and attempt to backtrack to find out what sort of error it was: https://github.com/erikrose/nose-progressive/blob/11bc55efe0fbd2b30b02a1914f22326f74da2985/noseprogressive/result.py#L111

Something like this would nicely separate computation and reporting:

def _classifyError(self, test, err):
"""Store info about an error, and return its error class.

If the error does not belong to any error class, return None.

"""
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 self.errorClasses.items():
if isclass(ec) and issubclass(ec, cls):
if isfail:
test.passed = False
storage.append((test, exc_info))
return cls
self.errors.append((test, exc_info))
test.passed = False

addError() would then call the above and do its reporting based on the return value.

Google Code Info:
Issue #: 400
Author: grinche...@gmail.com
Created On: 2011-02-21T21:43:53.000Z
Closed On: