Skip to content

Commit e98176c

Browse files
authored
Merge pull request #6501 from blueyed/test_color_yes
tests: terminal: harden test_color_yes
2 parents ac41f36 + 38fc208 commit e98176c

File tree

1 file changed

+65
-4
lines changed

1 file changed

+65
-4
lines changed

testing/test_terminal.py

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"red": "\x1b[31m",
2828
"green": "\x1b[32m",
2929
"yellow": "\x1b[33m",
30+
"bold": "\x1b[1m",
3031
"reset": "\x1b[0m",
3132
}
3233
RE_COLORS = {k: re.escape(v) for k, v in COLORS.items()}
@@ -833,10 +834,70 @@ def test_pass_no_output():
833834

834835

835836
def test_color_yes(testdir):
836-
testdir.makepyfile("def test_this(): assert 1")
837-
result = testdir.runpytest("--color=yes")
838-
assert "test session starts" in result.stdout.str()
839-
assert "\x1b[1m" in result.stdout.str()
837+
p1 = testdir.makepyfile(
838+
"""
839+
def fail():
840+
assert 0
841+
842+
def test_this():
843+
fail()
844+
"""
845+
)
846+
result = testdir.runpytest("--color=yes", str(p1))
847+
if sys.version_info < (3, 6):
848+
# py36 required for ordered markup
849+
output = result.stdout.str()
850+
assert "test session starts" in output
851+
assert "\x1b[1m" in output
852+
return
853+
result.stdout.fnmatch_lines(
854+
[
855+
line.format(**COLORS).replace("[", "[[]")
856+
for line in [
857+
"{bold}=*= test session starts =*={reset}",
858+
"collected 1 item",
859+
"",
860+
"test_color_yes.py {red}F{reset}{red} * [100%]{reset}",
861+
"",
862+
"=*= FAILURES =*=",
863+
"{red}{bold}_*_ test_this _*_{reset}",
864+
"",
865+
"{bold} def test_this():{reset}",
866+
"{bold}> fail(){reset}",
867+
"",
868+
"{bold}{red}test_color_yes.py{reset}:5: ",
869+
"_ _ * _ _*",
870+
"",
871+
"{bold} def fail():{reset}",
872+
"{bold}> assert 0{reset}",
873+
"{bold}{red}E assert 0{reset}",
874+
"",
875+
"{bold}{red}test_color_yes.py{reset}:2: AssertionError",
876+
"{red}=*= {red}{bold}1 failed{reset}{red} in *s{reset}{red} =*={reset}",
877+
]
878+
]
879+
)
880+
result = testdir.runpytest("--color=yes", "--tb=short", str(p1))
881+
result.stdout.fnmatch_lines(
882+
[
883+
line.format(**COLORS).replace("[", "[[]")
884+
for line in [
885+
"{bold}=*= test session starts =*={reset}",
886+
"collected 1 item",
887+
"",
888+
"test_color_yes.py {red}F{reset}{red} * [100%]{reset}",
889+
"",
890+
"=*= FAILURES =*=",
891+
"{red}{bold}_*_ test_this _*_{reset}",
892+
"{bold}{red}test_color_yes.py{reset}:5: in test_this",
893+
"{bold} fail(){reset}",
894+
"{bold}{red}test_color_yes.py{reset}:2: in fail",
895+
"{bold} assert 0{reset}",
896+
"{bold}{red}E assert 0{reset}",
897+
"{red}=*= {red}{bold}1 failed{reset}{red} in *s{reset}{red} =*={reset}",
898+
]
899+
]
900+
)
840901

841902

842903
def test_color_no(testdir):

0 commit comments

Comments
 (0)