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