run-tests: check if stream is a tty before using color
authorMatthieu Laneuville <matthieu.laneuville@octobus.net>
Tue, 18 Jul 2017 07:19:26 +0900
changeset 33561 2893face0af5
parent 33560 d4df141f90d1
child 33562 3cfabb6cfd51
run-tests: check if stream is a tty before using color Previous implementation (e80041832eec) checked only if sys.stderr was a tty which was less general. Also makes sure that colors is never used if pygments is not available, irrespective of --color flag value.
tests/run-tests.py
--- a/tests/run-tests.py	Fri Jul 14 21:44:29 2017 -0700
+++ b/tests/run-tests.py	Tue Jul 18 07:19:26 2017 +0900
@@ -101,9 +101,6 @@
     except ImportError:
         pass
 
-if not sys.stderr.isatty(): # check if the terminal is capable
-    with_color = False
-
 if sys.version_info > (3, 5, 0):
     PYTHON3 = True
     xrange = range # we use xrange in one place, and we'd rather not use range
@@ -416,13 +413,6 @@
         parser.error('--chg does not work when --with-hg is specified '
                      '(use --with-chg instead)')
 
-    global with_color
-    if options.color != 'auto':
-        if options.color == 'never':
-            with_color = False
-        else: # 'always', for testing purposes
-            with_color = True
-
     global useipv6
     if options.ipv6:
         useipv6 = checksocketfamily('AF_INET6')
@@ -1574,6 +1564,17 @@
         self.successes = []
         self.faildata = {}
 
+        global with_color
+        if not self.stream.isatty(): # check if the terminal is capable
+            with_color = False
+
+        if options.color != 'auto':
+            if options.color == 'never':
+                with_color = False
+            else: # 'always', for testing purposes
+                if pygmentspresent:
+                    with_color = True
+
     def addFailure(self, test, reason):
         self.failures.append((test, reason))