summaryrefslogtreecommitdiff
path: root/testlib.py
diff options
context:
space:
mode:
authorFabrice Douchant <Fabrice.Douchant@logilab.fr>2008-10-15 16:51:55 +0200
committerFabrice Douchant <Fabrice.Douchant@logilab.fr>2008-10-15 16:51:55 +0200
commit361640698cf03f9447c487ec9f38628bef9b72fd (patch)
treef3260838ea71e3c5fc43d3d269da7da25b73d0c6 /testlib.py
parenta7da658aad04d42c2f9e787fa9f9b26bf14e2d8b (diff)
downloadlogilab-common-361640698cf03f9447c487ec9f38628bef9b72fd.tar.gz
fix bug using os.isatty function
Diffstat (limited to 'testlib.py')
-rw-r--r--testlib.py20
1 files changed, 7 insertions, 13 deletions
diff --git a/testlib.py b/testlib.py
index 61ad306..f9cb971 100644
--- a/testlib.py
+++ b/testlib.py
@@ -58,17 +58,10 @@ except ImportError:
try:
from pygments import highlight, lexers, formatters
# only print in color if executed from a terminal
- PYGMENTS_FOUND = os.isatty
+ PYGMENTS_FOUND = True
except ImportError:
PYGMENTS_FOUND = False
-try:
- from logilab.common import textutils
- # only print in color if executed from a terminal
- TEXTUTILS_FOUND = os.isatty
-except ImportError:
- TEXTUTILS_FOUND = False
-
from logilab.common.deprecation import class_renamed, deprecated_function, \
obsolete
# pylint: disable-msg=W0622
@@ -77,6 +70,7 @@ from logilab.common.compat import set, enumerate, any
from logilab.common.modutils import load_module_from_name
from logilab.common.debugger import Debugger
from logilab.common.decorators import cached
+from logilab.common import textutils
__all__ = ['main', 'unittest_main', 'find_tests', 'run_test', 'spawn']
@@ -415,14 +409,14 @@ class SkipAwareTestResult(unittest._TextTestResult):
def printErrorList(self, flavour, errors):
for (_, descr), (test, err) in zip(self.descrs_for(flavour), errors):
- if PYGMENTS_FOUND:
+ if PYGMENTS_FOUND and os.isatty(self.stream.fileno()):
err = highlight(err, lexers.PythonLexer(),
formatters.terminal.TerminalFormatter())
self.stream.writeln(self.separator1)
- if TEXTUTILS_FOUND:
+ if os.isatty(self.stream.fileno()):
self.stream.writeln("%s: %s" % (
textutils.colorize_ansi(flavour, color='red'), descr))
- else :
+ else:
self.stream.writeln("%s: %s" % (flavour, descr))
self.stream.writeln(self.separator2)
@@ -559,12 +553,12 @@ class SkipAwareTextTestRunner(unittest.TextTestRunner):
(run, run != 1 and "s" or "", timeTaken))
self.stream.writeln()
if not result.wasSuccessful():
- if TEXTUTILS_FOUND:
+ if os.isatty(self.stream.fileno()):
self.stream.write(textutils.colorize_ansi("FAILED", color='red'))
else:
self.stream.write("FAILED")
else:
- if TEXTUTILS_FOUND:
+ if os.isatty(self.stream.fileno()):
self.stream.write(textutils.colorize_ansi("OK", color='green'))
else:
self.stream.write("OK")