]> Sergey Matveev's repositories - nose_gnuerrorformat.git/blob - nose_gnuerrorformat.py
6b0cf8f5b4423f51a26e69ce43badcede441f796
[nose_gnuerrorformat.git] / nose_gnuerrorformat.py
1 from os import getcwd
2 from os.path import commonpath
3 import traceback
4
5 from nose.plugins import Plugin
6
7
8 class NoseGNUErrorformatOutput(Plugin):
9     """Output tracebacks in GNU errorformat-compatible way.
10     """
11     name = 'gnuerrorformat'
12
13     def __init__(self):
14         super(NoseGNUErrorformatOutput, self).__init__()
15         self.cwd = getcwd()
16
17     def formatFailure(self, test, err):
18         return self.formatError(test, err)
19
20     def formatError(self, _, err):
21         ec, ev, tb = err
22         if not isinstance(ev, str):
23             ev = traceback.format_exception_only(ec, ev)[0]
24         evs = [ev, "-----BEGIN GNU errorformat-----"]
25         for (filen, linen, funcn, txt) in traceback.extract_tb(tb):
26             if not filen.startswith(self.cwd):
27                 continue
28             filen = filen[len(self.cwd) + 1:]
29             evs.append("{}:{:d}:0: {}: {}".format(filen, linen, funcn, txt))
30         evs.append("-----END GNU errorformat-----")
31         return ec, "\n".join(evs), tb