@@ -48,20 +48,30 @@ def read_out_err(self) -> tuple[str, str]:
48
48
@pytest .mark .parametrize ("color" , [True , False ], ids = ["color" , "no_color" ])
49
49
@pytest .mark .parametrize (("out" , "err" ), [("out" , "err" ), ("" , "" )], ids = ["simple" , "nothing" ])
50
50
@pytest .mark .parametrize ("show" , [True , False ], ids = ["show" , "no_show" ])
51
+ @pytest .mark .parametrize (
52
+ "stderr_color" ,
53
+ ["RED" , "YELLOW" , "RESET" ],
54
+ ids = ["stderr_color_default" , "stderr_color_yellow" , "stderr_color_reset" ],
55
+ )
51
56
def test_local_execute_basic_pass ( # noqa: PLR0913
52
57
caplog : LogCaptureFixture ,
53
58
os_env : dict [str , str ],
54
59
out : str ,
55
60
err : str ,
56
61
show : bool ,
57
62
color : bool ,
63
+ stderr_color : str ,
58
64
) -> None :
59
65
caplog .set_level (logging .NOTSET )
60
66
executor = LocalSubProcessExecutor (colored = color )
67
+
68
+ tox_env = MagicMock ()
69
+ tox_env .conf ._conf .options .stderr_color = stderr_color # noqa: SLF001
61
70
code = f"import sys; print({ out !r} , end=''); print({ err !r} , end='', file=sys.stderr)"
62
71
request = ExecuteRequest (cmd = [sys .executable , "-c" , code ], cwd = Path (), env = os_env , stdin = StdinSource .OFF , run_id = "" )
63
72
out_err = FakeOutErr ()
64
- with executor .call (request , show = show , out_err = out_err .out_err , env = MagicMock ()) as status :
73
+
74
+ with executor .call (request , show = show , out_err = out_err .out_err , env = tox_env ) as status :
65
75
while status .exit_code is None : # pragma: no branch
66
76
status .wait ()
67
77
assert status .out == out .encode ()
@@ -77,7 +87,7 @@ def test_local_execute_basic_pass( # noqa: PLR0913
77
87
out_got , err_got = out_err .read_out_err ()
78
88
if show :
79
89
assert out_got == out
80
- expected = ( f"{ Fore . RED } { err } { Fore .RESET } " if color else err ) if err else ""
90
+ expected = f"{ getattr ( Fore , stderr_color ) } { err } { Fore .RESET } " if color and err else err
81
91
assert err_got == expected
82
92
else :
83
93
assert not out_got
0 commit comments