summaryrefslogtreecommitdiff
path: root/testlib.py
diff options
context:
space:
mode:
authorFabrice Douchant <Fabrice.Douchant@logilab.fr>2008-10-15 11:04:28 +0200
committerFabrice Douchant <Fabrice.Douchant@logilab.fr>2008-10-15 11:04:28 +0200
commit9e229b4e42e4cdb165f48457958f4d76a1443700 (patch)
treebe0c0fdfd45bf9d4e50d44b58b35c1467422ce31 /testlib.py
parent87ee3e314de58b2a9be4de73a71fdc403f758c73 (diff)
downloadlogilab-common-9e229b4e42e4cdb165f48457958f4d76a1443700.tar.gz
add colors in traceback if PYGMENTS is available
Diffstat (limited to 'testlib.py')
-rw-r--r--testlib.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/testlib.py b/testlib.py
index 0838653..cc87f4d 100644
--- a/testlib.py
+++ b/testlib.py
@@ -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)