tests: terminal: harden/improve test_color_yes
This commit is contained in:
parent
ac41f36a02
commit
38fc208205
|
@ -27,6 +27,7 @@ COLORS = {
|
||||||
"red": "\x1b[31m",
|
"red": "\x1b[31m",
|
||||||
"green": "\x1b[32m",
|
"green": "\x1b[32m",
|
||||||
"yellow": "\x1b[33m",
|
"yellow": "\x1b[33m",
|
||||||
|
"bold": "\x1b[1m",
|
||||||
"reset": "\x1b[0m",
|
"reset": "\x1b[0m",
|
||||||
}
|
}
|
||||||
RE_COLORS = {k: re.escape(v) for k, v in COLORS.items()}
|
RE_COLORS = {k: re.escape(v) for k, v in COLORS.items()}
|
||||||
|
@ -833,10 +834,70 @@ def test_pass_output_reporting(testdir):
|
||||||
|
|
||||||
|
|
||||||
def test_color_yes(testdir):
|
def test_color_yes(testdir):
|
||||||
testdir.makepyfile("def test_this(): assert 1")
|
p1 = testdir.makepyfile(
|
||||||
result = testdir.runpytest("--color=yes")
|
"""
|
||||||
assert "test session starts" in result.stdout.str()
|
def fail():
|
||||||
assert "\x1b[1m" in result.stdout.str()
|
assert 0
|
||||||
|
|
||||||
|
def test_this():
|
||||||
|
fail()
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
result = testdir.runpytest("--color=yes", str(p1))
|
||||||
|
if sys.version_info < (3, 6):
|
||||||
|
# py36 required for ordered markup
|
||||||
|
output = result.stdout.str()
|
||||||
|
assert "test session starts" in output
|
||||||
|
assert "\x1b[1m" in output
|
||||||
|
return
|
||||||
|
result.stdout.fnmatch_lines(
|
||||||
|
[
|
||||||
|
line.format(**COLORS).replace("[", "[[]")
|
||||||
|
for line in [
|
||||||
|
"{bold}=*= test session starts =*={reset}",
|
||||||
|
"collected 1 item",
|
||||||
|
"",
|
||||||
|
"test_color_yes.py {red}F{reset}{red} * [100%]{reset}",
|
||||||
|
"",
|
||||||
|
"=*= FAILURES =*=",
|
||||||
|
"{red}{bold}_*_ test_this _*_{reset}",
|
||||||
|
"",
|
||||||
|
"{bold} def test_this():{reset}",
|
||||||
|
"{bold}> fail(){reset}",
|
||||||
|
"",
|
||||||
|
"{bold}{red}test_color_yes.py{reset}:5: ",
|
||||||
|
"_ _ * _ _*",
|
||||||
|
"",
|
||||||
|
"{bold} def fail():{reset}",
|
||||||
|
"{bold}> assert 0{reset}",
|
||||||
|
"{bold}{red}E assert 0{reset}",
|
||||||
|
"",
|
||||||
|
"{bold}{red}test_color_yes.py{reset}:2: AssertionError",
|
||||||
|
"{red}=*= {red}{bold}1 failed{reset}{red} in *s{reset}{red} =*={reset}",
|
||||||
|
]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
result = testdir.runpytest("--color=yes", "--tb=short", str(p1))
|
||||||
|
result.stdout.fnmatch_lines(
|
||||||
|
[
|
||||||
|
line.format(**COLORS).replace("[", "[[]")
|
||||||
|
for line in [
|
||||||
|
"{bold}=*= test session starts =*={reset}",
|
||||||
|
"collected 1 item",
|
||||||
|
"",
|
||||||
|
"test_color_yes.py {red}F{reset}{red} * [100%]{reset}",
|
||||||
|
"",
|
||||||
|
"=*= FAILURES =*=",
|
||||||
|
"{red}{bold}_*_ test_this _*_{reset}",
|
||||||
|
"{bold}{red}test_color_yes.py{reset}:5: in test_this",
|
||||||
|
"{bold} fail(){reset}",
|
||||||
|
"{bold}{red}test_color_yes.py{reset}:2: in fail",
|
||||||
|
"{bold} assert 0{reset}",
|
||||||
|
"{bold}{red}E assert 0{reset}",
|
||||||
|
"{red}=*= {red}{bold}1 failed{reset}{red} in *s{reset}{red} =*={reset}",
|
||||||
|
]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_color_no(testdir):
|
def test_color_no(testdir):
|
||||||
|
|
Loading…
Reference in New Issue