From 16c8be41c97e5fa7395ca9d83a7562c162e456d1 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Thu, 3 Dec 2020 22:45:53 +0100 Subject: [PATCH] report fragment: strip ansi colors from junit XML Jenkins does support showing ANSI colors on the web, but apparently not in the junit results output. Strip ansi colors from report fragment text, to make it less annoying to read those on jenkins. Change-Id: I656ecc23bbfd3f25bdf012c890e0c998168844d3 --- src/osmo_gsm_tester/core/log.py | 1 + src/osmo_gsm_tester/core/report.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/osmo_gsm_tester/core/log.py b/src/osmo_gsm_tester/core/log.py index a573f051..f7c210a1 100644 --- a/src/osmo_gsm_tester/core/log.py +++ b/src/osmo_gsm_tester/core/log.py @@ -22,6 +22,7 @@ import sys import time import traceback import atexit +import re from datetime import datetime # we need this for strftime as the one from time doesn't carry microsecond info from inspect import getframeinfo, stack diff --git a/src/osmo_gsm_tester/core/report.py b/src/osmo_gsm_tester/core/report.py index c5e185ff..476fa0b8 100644 --- a/src/osmo_gsm_tester/core/report.py +++ b/src/osmo_gsm_tester/core/report.py @@ -41,11 +41,15 @@ if sys.maxunicode >= 0x10000: # not narrow build invalid_xml_char_ranges_str = ['%s-%s' % (chr(low), chr(high)) for (low, high) in invalid_xml_char_ranges] invalid_xml_char_ranges_regex = re.compile('[%s]' % ''.join(invalid_xml_char_ranges_str)) +ansi_color_re = re.compile('\033[0-9;]{1,4}m') def escape_xml_invalid_characters(str): replacement_char = '\uFFFD' # Unicode replacement character return invalid_xml_char_ranges_regex.sub(replacement_char, escape(str)) +def strip_ansi_colors(text): + return ''.join(ansi_color_re.split(text)) + def hash_info_to_junit(testsuite, hash_info): properties = et.SubElement(testsuite, 'properties') for key, val in hash_info.items(): @@ -156,7 +160,7 @@ def suite_to_junit(suite): if report_fragment.output: sout = et.SubElement(el, 'system-out') - sout.text = escape_xml_invalid_characters(report_fragment.output) + sout.text = escape_xml_invalid_characters(strip_ansi_colors(report_fragment.output)) testsuite.append(el) testsuite.set('errors', str(errors))