Skip to contentSkip to conversation

tests: py: Don't colorize output if stderr is redirected

PATCH In review Phil Sutter 2 participants 2 messages Apr 8, 2022 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 tests: py: Don't colorize output if stderr is redirected

Cover for calls with '2>/tmp/log' and avoid printing escape sequences to that file. One could still keep colored output on stdout, but that required a printing routine for non-errors.

---
 tests/py/nft-test.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/py/nft-test.py +1 -1
index 04dac8d77b25f..b66a33c21f661 100755
@@ -39,7 +39,7 @@ signal_received = 0
 
 
 class Colors:
-    if sys.stdout.isatty():
+    if sys.stdout.isatty() and sys.stderr.isatty():
         HEADER = '\033[95m'
         GREEN = '\033[92m'
         YELLOW = '\033[93m'
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 3 lines · Phil Sutter

Cover for calls with '2>/tmp/log' and avoid printing escape sequences to that file. One could still keep colored output on stdout, but that required a printing routine for non-errors.

Thanks! Please push.