@@ -47,20 +47,28 @@ def read_out_err(self) -> tuple[str, str]:
4747@pytest .mark .parametrize ("color" , [True , False ], ids = ["color" , "no_color" ])
4848@pytest .mark .parametrize (("out" , "err" ), [("out" , "err" ), ("" , "" )], ids = ["simple" , "nothing" ])
4949@pytest .mark .parametrize ("show" , [True , False ], ids = ["show" , "no_show" ])
50+ @pytest .mark .parametrize (
51+ "stderr_color" , ["RED" , "YELLOW" , "0" ], ids = ["stderr_color_default" , "stderr_color_yellow" , "stderr_color_no" ]
52+ )
5053def test_local_execute_basic_pass ( # noqa: PLR0913
5154 caplog : LogCaptureFixture ,
5255 os_env : dict [str , str ],
5356 out : str ,
5457 err : str ,
5558 show : bool ,
5659 color : bool ,
60+ stderr_color : str ,
5761) -> None :
5862 caplog .set_level (logging .NOTSET )
5963 executor = LocalSubProcessExecutor (colored = color )
64+
65+ tox_env = MagicMock ()
66+ tox_env .conf ._conf .options .stderr_color = stderr_color # noqa: SLF001
6067 code = f"import sys; print({ out !r} , end=''); print({ err !r} , end='', file=sys.stderr)"
6168 request = ExecuteRequest (cmd = [sys .executable , "-c" , code ], cwd = Path (), env = os_env , stdin = StdinSource .OFF , run_id = "" )
6269 out_err = FakeOutErr ()
63- with executor .call (request , show = show , out_err = out_err .out_err , env = MagicMock ()) as status :
70+
71+ with executor .call (request , show = show , out_err = out_err .out_err , env = tox_env ) as status :
6472 while status .exit_code is None : # pragma: no branch
6573 status .wait ()
6674 assert status .out == out .encode ()
@@ -76,7 +84,10 @@ def test_local_execute_basic_pass( # noqa: PLR0913
7684 out_got , err_got = out_err .read_out_err ()
7785 if show :
7886 assert out_got == out
79- expected = (f"{ Fore .RED } { err } { Fore .RESET } " if color else err ) if err else ""
87+ if not color or stderr_color == "0" : # noqa: SIM108
88+ expected = err
89+ else :
90+ expected = f"{ Fore .__dict__ [stderr_color ]} { err } { Fore .RESET } "
8091 assert err_got == expected
8192 else :
8293 assert not out_got
0 commit comments