summaryrefslogtreecommitdiff
path: root/testing/test_terminal.py
diff options
context:
space:
mode:
authorDaniel Hahler <git@thequod.de>2020-01-18 12:43:38 +0100
committerDaniel Hahler <git@thequod.de>2020-01-18 13:16:27 +0100
commitd4d04e7f25ac534d60e1c3a60209be080dffce21 (patch)
tree24f14b70a905db1751309a42f8b5ede80be51676 /testing/test_terminal.py
parent4f0eec2022c9c25c98c719f1745f57e9afe04274 (diff)
downloadpytest-d4d04e7f25ac534d60e1c3a60209be080dffce21.tar.gz
test_terminal: improve color handling
Diffstat (limited to 'testing/test_terminal.py')
-rw-r--r--testing/test_terminal.py32
1 files changed, 17 insertions, 15 deletions
diff --git a/testing/test_terminal.py b/testing/test_terminal.py
index 37f1eca89..16fee37d6 100644
--- a/testing/test_terminal.py
+++ b/testing/test_terminal.py
@@ -3,6 +3,7 @@ terminal reporting of the full testing process.
"""
import collections
import os
+import re
import sys
import textwrap
from io import StringIO
@@ -21,10 +22,14 @@ from _pytest.terminal import getreportopt
from _pytest.terminal import TerminalReporter
DistInfo = collections.namedtuple("DistInfo", ["project_name", "version"])
-RED = r"\x1b\[31m"
-GREEN = r"\x1b\[32m"
-YELLOW = r"\x1b\[33m"
-RESET = r"\x1b\[0m"
+
+COLORS = {
+ "red": "\x1b[31m",
+ "green": "\x1b[32m",
+ "yellow": "\x1b[33m",
+ "reset": "\x1b[0m",
+}
+RE_COLORS = {k: re.escape(v) for k, v in COLORS.items()}
class Option:
@@ -1548,18 +1553,15 @@ class TestProgressOutputStyle:
def test_foobar(i): raise ValueError()
""",
)
- output = testdir.runpytest()
- output.stdout.re_match_lines(
+ result = testdir.runpytest()
+ result.stdout.re_match_lines(
[
- r"test_bar.py ({green}\.{reset}){{10}}{green} \s+ \[ 50%\]{reset}".format(
- green=GREEN, reset=RESET
- ),
- r"test_foo.py ({green}\.{reset}){{5}}{yellow} \s+ \[ 75%\]{reset}".format(
- green=GREEN, reset=RESET, yellow=YELLOW
- ),
- r"test_foobar.py ({red}F{reset}){{5}}{red} \s+ \[100%\]{reset}".format(
- reset=RESET, red=RED
- ),
+ line.format(**RE_COLORS)
+ for line in [
+ r"test_bar.py ({green}\.{reset}){{10}}{green} \s+ \[ 50%\]{reset}",
+ r"test_foo.py ({green}\.{reset}){{5}}{yellow} \s+ \[ 75%\]{reset}",
+ r"test_foobar.py ({red}F{reset}){{5}}{red} \s+ \[100%\]{reset}",
+ ]
]
)