test_terminal: improve color handling
This commit is contained in:
parent
4f0eec2022
commit
d4d04e7f25
|
@ -3,6 +3,7 @@ terminal reporting of the full testing process.
|
||||||
"""
|
"""
|
||||||
import collections
|
import collections
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
@ -21,10 +22,14 @@ from _pytest.terminal import getreportopt
|
||||||
from _pytest.terminal import TerminalReporter
|
from _pytest.terminal import TerminalReporter
|
||||||
|
|
||||||
DistInfo = collections.namedtuple("DistInfo", ["project_name", "version"])
|
DistInfo = collections.namedtuple("DistInfo", ["project_name", "version"])
|
||||||
RED = r"\x1b\[31m"
|
|
||||||
GREEN = r"\x1b\[32m"
|
COLORS = {
|
||||||
YELLOW = r"\x1b\[33m"
|
"red": "\x1b[31m",
|
||||||
RESET = r"\x1b\[0m"
|
"green": "\x1b[32m",
|
||||||
|
"yellow": "\x1b[33m",
|
||||||
|
"reset": "\x1b[0m",
|
||||||
|
}
|
||||||
|
RE_COLORS = {k: re.escape(v) for k, v in COLORS.items()}
|
||||||
|
|
||||||
|
|
||||||
class Option:
|
class Option:
|
||||||
|
@ -1548,18 +1553,15 @@ class TestProgressOutputStyle:
|
||||||
def test_foobar(i): raise ValueError()
|
def test_foobar(i): raise ValueError()
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
output = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
output.stdout.re_match_lines(
|
result.stdout.re_match_lines(
|
||||||
[
|
[
|
||||||
r"test_bar.py ({green}\.{reset}){{10}}{green} \s+ \[ 50%\]{reset}".format(
|
line.format(**RE_COLORS)
|
||||||
green=GREEN, reset=RESET
|
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}".format(
|
r"test_foo.py ({green}\.{reset}){{5}}{yellow} \s+ \[ 75%\]{reset}",
|
||||||
green=GREEN, reset=RESET, yellow=YELLOW
|
r"test_foobar.py ({red}F{reset}){{5}}{red} \s+ \[100%\]{reset}",
|
||||||
),
|
]
|
||||||
r"test_foobar.py ({red}F{reset}){{5}}{red} \s+ \[100%\]{reset}".format(
|
|
||||||
reset=RESET, red=RED
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue