Put a 'reset' color in front of the highlighting
When doing the highlighting, some lexers will not set the initial color explicitly, which mmay lead to the red from the errors being propagated to the start of the expression
This commit is contained in:
parent
a536f49d91
commit
c5da533c79
|
@ -223,7 +223,7 @@ class TerminalWriter:
|
||||||
style=os.getenv("PYTEST_THEME"),
|
style=os.getenv("PYTEST_THEME"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return highlighted
|
return "\x1b[0m" + highlighted
|
||||||
except pygments.util.ClassNotFound:
|
except pygments.util.ClassNotFound:
|
||||||
raise UsageError(
|
raise UsageError(
|
||||||
"PYTEST_THEME environment variable had an invalid value: '{}'. "
|
"PYTEST_THEME environment variable had an invalid value: '{}'. "
|
||||||
|
|
|
@ -254,7 +254,7 @@ class TestTerminalWriterLineWidth:
|
||||||
pytest.param(
|
pytest.param(
|
||||||
True,
|
True,
|
||||||
True,
|
True,
|
||||||
"{kw}assert{hl-reset} {number}0{hl-reset}{endline}\n",
|
"{reset}{kw}assert{hl-reset} {number}0{hl-reset}{endline}\n",
|
||||||
id="with markup and code_highlight",
|
id="with markup and code_highlight",
|
||||||
),
|
),
|
||||||
pytest.param(
|
pytest.param(
|
||||||
|
|
|
@ -1945,7 +1945,7 @@ def test_reprcompare_verbose_long() -> None:
|
||||||
}
|
}
|
||||||
""",
|
""",
|
||||||
[
|
[
|
||||||
"{bold}{red}E {light-gray} {hl-reset} {{{endline}{reset}",
|
"{bold}{red}E {reset}{light-gray} {hl-reset} {{{endline}{reset}",
|
||||||
"{bold}{red}E {light-gray} {hl-reset} 'number-is-1': 1,{endline}{reset}",
|
"{bold}{red}E {light-gray} {hl-reset} 'number-is-1': 1,{endline}{reset}",
|
||||||
"{bold}{red}E {light-green}+ 'number-is-5': 5,{hl-reset}{endline}{reset}",
|
"{bold}{red}E {light-green}+ 'number-is-5': 5,{hl-reset}{endline}{reset}",
|
||||||
],
|
],
|
||||||
|
|
|
@ -1268,13 +1268,13 @@ def test_color_yes(pytester: Pytester, color_mapping) -> None:
|
||||||
"=*= FAILURES =*=",
|
"=*= FAILURES =*=",
|
||||||
"{red}{bold}_*_ test_this _*_{reset}",
|
"{red}{bold}_*_ test_this _*_{reset}",
|
||||||
"",
|
"",
|
||||||
" {kw}def{hl-reset} {function}test_this{hl-reset}():{endline}",
|
" {reset}{kw}def{hl-reset} {function}test_this{hl-reset}():{endline}",
|
||||||
"> fail(){endline}",
|
"> fail(){endline}",
|
||||||
"",
|
"",
|
||||||
"{bold}{red}test_color_yes.py{reset}:5: ",
|
"{bold}{red}test_color_yes.py{reset}:5: ",
|
||||||
"_ _ * _ _*",
|
"_ _ * _ _*",
|
||||||
"",
|
"",
|
||||||
" {kw}def{hl-reset} {function}fail{hl-reset}():{endline}",
|
" {reset}{kw}def{hl-reset} {function}fail{hl-reset}():{endline}",
|
||||||
"> {kw}assert{hl-reset} {number}0{hl-reset}{endline}",
|
"> {kw}assert{hl-reset} {number}0{hl-reset}{endline}",
|
||||||
"{bold}{red}E assert 0{reset}",
|
"{bold}{red}E assert 0{reset}",
|
||||||
"",
|
"",
|
||||||
|
@ -1295,9 +1295,9 @@ def test_color_yes(pytester: Pytester, color_mapping) -> None:
|
||||||
"=*= FAILURES =*=",
|
"=*= FAILURES =*=",
|
||||||
"{red}{bold}_*_ test_this _*_{reset}",
|
"{red}{bold}_*_ test_this _*_{reset}",
|
||||||
"{bold}{red}test_color_yes.py{reset}:5: in test_this",
|
"{bold}{red}test_color_yes.py{reset}:5: in test_this",
|
||||||
" fail(){endline}",
|
" {reset}fail(){endline}",
|
||||||
"{bold}{red}test_color_yes.py{reset}:2: in fail",
|
"{bold}{red}test_color_yes.py{reset}:2: in fail",
|
||||||
" {kw}assert{hl-reset} {number}0{hl-reset}{endline}",
|
" {reset}{kw}assert{hl-reset} {number}0{hl-reset}{endline}",
|
||||||
"{bold}{red}E assert 0{reset}",
|
"{bold}{red}E assert 0{reset}",
|
||||||
"{red}=*= {red}{bold}1 failed{reset}{red} in *s{reset}{red} =*={reset}",
|
"{red}=*= {red}{bold}1 failed{reset}{red} in *s{reset}{red} =*={reset}",
|
||||||
]
|
]
|
||||||
|
@ -2507,7 +2507,7 @@ class TestCodeHighlight:
|
||||||
result.stdout.fnmatch_lines(
|
result.stdout.fnmatch_lines(
|
||||||
color_mapping.format_for_fnmatch(
|
color_mapping.format_for_fnmatch(
|
||||||
[
|
[
|
||||||
" {kw}def{hl-reset} {function}test_foo{hl-reset}():{endline}",
|
" {reset}{kw}def{hl-reset} {function}test_foo{hl-reset}():{endline}",
|
||||||
"> {kw}assert{hl-reset} {number}1{hl-reset} == {number}10{hl-reset}{endline}",
|
"> {kw}assert{hl-reset} {number}1{hl-reset} == {number}10{hl-reset}{endline}",
|
||||||
"{bold}{red}E assert 1 == 10{reset}",
|
"{bold}{red}E assert 1 == 10{reset}",
|
||||||
]
|
]
|
||||||
|
@ -2529,7 +2529,7 @@ class TestCodeHighlight:
|
||||||
result.stdout.fnmatch_lines(
|
result.stdout.fnmatch_lines(
|
||||||
color_mapping.format_for_fnmatch(
|
color_mapping.format_for_fnmatch(
|
||||||
[
|
[
|
||||||
" {kw}def{hl-reset} {function}test_foo{hl-reset}():{endline}",
|
" {reset}{kw}def{hl-reset} {function}test_foo{hl-reset}():{endline}",
|
||||||
" {print}print{hl-reset}({str}'''{hl-reset}{str}{hl-reset}",
|
" {print}print{hl-reset}({str}'''{hl-reset}{str}{hl-reset}",
|
||||||
"> {str} {hl-reset}{str}'''{hl-reset}); {kw}assert{hl-reset} {number}0{hl-reset}{endline}",
|
"> {str} {hl-reset}{str}'''{hl-reset}); {kw}assert{hl-reset} {number}0{hl-reset}{endline}",
|
||||||
"{bold}{red}E assert 0{reset}",
|
"{bold}{red}E assert 0{reset}",
|
||||||
|
@ -2552,7 +2552,7 @@ class TestCodeHighlight:
|
||||||
result.stdout.fnmatch_lines(
|
result.stdout.fnmatch_lines(
|
||||||
color_mapping.format_for_fnmatch(
|
color_mapping.format_for_fnmatch(
|
||||||
[
|
[
|
||||||
" {kw}def{hl-reset} {function}test_foo{hl-reset}():{endline}",
|
" {reset}{kw}def{hl-reset} {function}test_foo{hl-reset}():{endline}",
|
||||||
"> {kw}assert{hl-reset} {number}1{hl-reset} == {number}10{hl-reset}{endline}",
|
"> {kw}assert{hl-reset} {number}1{hl-reset} == {number}10{hl-reset}{endline}",
|
||||||
"{bold}{red}E assert 1 == 10{reset}",
|
"{bold}{red}E assert 1 == 10{reset}",
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue