@@ -48,20 +48,30 @@ def read_out_err(self) -> tuple[str, str]:
4848@pytest .mark .parametrize ("color" , [True , False ], ids = ["color" , "no_color" ])
4949@pytest .mark .parametrize (("out" , "err" ), [("out" , "err" ), ("" , "" )], ids = ["simple" , "nothing" ])
5050@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+ )
5156def test_local_execute_basic_pass ( # noqa: PLR0913
5257 caplog : LogCaptureFixture ,
5358 os_env : dict [str , str ],
5459 out : str ,
5560 err : str ,
5661 show : bool ,
5762 color : bool ,
63+ stderr_color : str ,
5864) -> None :
5965 caplog .set_level (logging .NOTSET )
6066 executor = LocalSubProcessExecutor (colored = color )
67+
68+ tox_env = MagicMock ()
69+ tox_env .conf ._conf .options .stderr_color = stderr_color # noqa: SLF001
6170 code = f"import sys; print({ out !r} , end=''); print({ err !r} , end='', file=sys.stderr)"
6271 request = ExecuteRequest (cmd = [sys .executable , "-c" , code ], cwd = Path (), env = os_env , stdin = StdinSource .OFF , run_id = "" )
6372 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 :
6575 while status .exit_code is None : # pragma: no branch
6676 status .wait ()
6777 assert status .out == out .encode ()
@@ -77,7 +87,7 @@ def test_local_execute_basic_pass( # noqa: PLR0913
7787 out_got , err_got = out_err .read_out_err ()
7888 if show :
7989 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
8191 assert err_got == expected
8292 else :
8393 assert not out_got
0 commit comments