diff options
author | Fabrice Douchant <Fabrice.Douchant@logilab.fr> | 2008-10-15 11:04:28 +0200 |
---|---|---|
committer | Fabrice Douchant <Fabrice.Douchant@logilab.fr> | 2008-10-15 11:04:28 +0200 |
commit | 9e229b4e42e4cdb165f48457958f4d76a1443700 (patch) | |
tree | be0c0fdfd45bf9d4e50d44b58b35c1467422ce31 /testlib.py | |
parent | 87ee3e314de58b2a9be4de73a71fdc403f758c73 (diff) | |
download | logilab-common-9e229b4e42e4cdb165f48457958f4d76a1443700.tar.gz |
add colors in traceback if PYGMENTS is available
Diffstat (limited to 'testlib.py')
-rw-r--r-- | testlib.py | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -55,6 +55,13 @@ except ImportError: pass test_support = TestSupport() +try: + from pygments import highlight, lexers, formatters + # only print in color if executed from a terminal + PYGMENTS_FOUND = os.isatty +except ImportError: + PYGMENTS_FOUND = False + from logilab.common.deprecation import class_renamed, deprecated_function, \ obsolete # pylint: disable-msg=W0622 @@ -401,6 +408,9 @@ class SkipAwareTestResult(unittest._TextTestResult): def printErrorList(self, flavour, errors): for (_, descr), (test, err) in zip(self.descrs_for(flavour), errors): + if PYGMENTS_FOUND: + err = highlight(err, lexers.PythonLexer(), + formatters.terminal.TerminalFormatter()) self.stream.writeln(self.separator1) self.stream.writeln("%s: %s" % (flavour, descr)) self.stream.writeln(self.separator2) |