aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/pytest/yatest_tools.py
diff options
context:
space:
mode:
authorprettyboy <prettyboy@yandex-team.com>2023-01-20 16:33:46 +0300
committerprettyboy <prettyboy@yandex-team.com>2023-01-20 16:33:46 +0300
commitc6a952a6e1eda08c6e1742ec1170691cec3670da (patch)
treeb28ddb53b5ce194482167c04cadc532353b1193d /library/python/pytest/yatest_tools.py
parent5c6ff1d7c6908ac41bcd7b4711c1396809d4b0a8 (diff)
downloadydb-c6a952a6e1eda08c6e1742ec1170691cec3670da.tar.gz
[library/python/pytest] Better py3 colorization
Diffstat (limited to 'library/python/pytest/yatest_tools.py')
-rw-r--r--library/python/pytest/yatest_tools.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/library/python/pytest/yatest_tools.py b/library/python/pytest/yatest_tools.py
index bdcd0cc0b1..0c3138a9fa 100644
--- a/library/python/pytest/yatest_tools.py
+++ b/library/python/pytest/yatest_tools.py
@@ -385,3 +385,37 @@ def _unify_path(path):
raise MissingTestModule("Can't find proper module for '{}' path among: {}".format(path, suff_tree))
else:
return path
+
+
+def colorize_pytest_error(text):
+ error_prefix = "E "
+ blocks = [text]
+
+ while True:
+ text = blocks.pop()
+
+ err_start = text.find(error_prefix, 1)
+ if err_start == -1:
+ return ''.join(blocks + [text])
+
+ for pos in range(err_start + 1, len(text) - 1):
+ if text[pos] == '\n':
+ if not text[pos + 1:].startswith(error_prefix):
+ err_end = pos + 1
+ break
+ else:
+ err_end = len(text)
+
+ bt, error, tail = text[:err_start], text[err_start:err_end], text[err_end:]
+
+ filters = [
+ # File path, line number and function name
+ (re.compile(r"^(.*?):(\d+): in (\S+)", flags=re.MULTILINE),
+ r"[[unimp]]\1[[rst]]:[[alt2]]\2[[rst]]: in [[alt1]]\3[[rst]]"),
+ ]
+ for regex, substitution in filters:
+ bt = regex.sub(substitution, bt)
+
+ blocks.append(bt)
+ blocks.append('[[bad]]' + error)
+ blocks.append(tail)