bobber6467 / python-nose

Automatically exported from code.google.com/p/python-nose
0 stars 0 forks source link

Factor out errorClass support #400

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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/11bc55efe0fbd2b30b02a1914f2232
6f74da2985/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.

Original issue reported on code.google.com by grinche...@gmail.com on 21 Feb 2011 at 9:43