diff --git a/docs/changelog/3171.feature.rst b/docs/changelog/3171.feature.rst new file mode 100644 index 000000000..58b754d6a --- /dev/null +++ b/docs/changelog/3171.feature.rst @@ -0,0 +1 @@ +Always pass ``FORCE_COLOR`` and ``NO_COLOR`` to the environment diff --git a/src/tox/tox_env/api.py b/src/tox/tox_env/api.py index 6c93d2f98..5b4bb7c30 100644 --- a/src/tox/tox_env/api.py +++ b/src/tox/tox_env/api.py @@ -220,6 +220,8 @@ def _default_pass_env(self) -> list[str]: # noqa: PLR6301 "LD_LIBRARY_PATH", # location of libs "LDFLAGS", # linker flags "HOME", # needed for `os.path.expanduser()` on non-Windows systems + "FORCE_COLOR", # force color output + "NO_COLOR", # disable color output ] if sys.stdout.isatty(): # if we're on a interactive shell pass on the TERM env.append("TERM") diff --git a/tests/session/cmd/test_show_config.py b/tests/session/cmd/test_show_config.py index af565e442..b852a40d0 100644 --- a/tests/session/cmd/test_show_config.py +++ b/tests/session/cmd/test_show_config.py @@ -123,8 +123,11 @@ def test_pass_env_config_default(tox_project: ToxProjectCreator, stdout_is_atty: + (["APPDATA"] if is_win else []) + ["CC", "CCSHARED", "CFLAGS"] + (["COMSPEC"] if is_win else []) - + ["CPPFLAGS", "CURL_CA_BUNDLE", "CXX", "HOME", "LANG", "LANGUAGE", "LDFLAGS", "LD_LIBRARY_PATH"] - + (["MSYSTEM", "NUMBER_OF_PROCESSORS", "PATHEXT"] if is_win else []) + + ["CPPFLAGS", "CURL_CA_BUNDLE", "CXX", "FORCE_COLOR", "HOME", "LANG"] + + ["LANGUAGE", "LDFLAGS", "LD_LIBRARY_PATH"] + + (["MSYSTEM"] if is_win else []) + + ["NO_COLOR"] + + (["NUMBER_OF_PROCESSORS", "PATHEXT"] if is_win else []) + ["PIP_*", "PKG_CONFIG", "PKG_CONFIG_PATH", "PKG_CONFIG_SYSROOT_DIR"] + (["PROCESSOR_ARCHITECTURE"] if is_win else []) + (["PROGRAMDATA"] if is_win else [])