From d216ab4d99432b24b46aa1843681fbec8223cc47 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Thu, 14 Dec 2023 22:57:54 +0100 Subject: [PATCH] Always pass PY_COLORS to the environment The environment variable is a popular way to force color output, an example being pytest being run under a CI system. --- docs/changelog/3171.feature.rst | 1 + src/tox/tox_env/api.py | 2 ++ tests/session/cmd/test_show_config.py | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 docs/changelog/3171.feature.rst diff --git a/docs/changelog/3171.feature.rst b/docs/changelog/3171.feature.rst new file mode 100644 index 0000000000..1527d0f4fe --- /dev/null +++ b/docs/changelog/3171.feature.rst @@ -0,0 +1 @@ +Always ``PY_COLORS`` to the environment diff --git a/src/tox/tox_env/api.py b/src/tox/tox_env/api.py index 45bbc5ce1c..73b42ad10f 100644 --- a/src/tox/tox_env/api.py +++ b/src/tox/tox_env/api.py @@ -219,6 +219,8 @@ def _default_pass_env(self) -> list[str]: "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 f5829294b1..16803560d9 100644 --- a/tests/session/cmd/test_show_config.py +++ b/tests/session/cmd/test_show_config.py @@ -123,7 +123,8 @@ 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"] + + ["CPPFLAGS", "CURL_CA_BUNDLE", "CXX", "FORCE_COLOR", "HOME", "LANG"] + + ["LANGUAGE", "LDFLAGS", "LD_LIBRARY_PATH", "NO_COLOR"] + (["MSYSTEM", "NUMBER_OF_PROCESSORS", "PATHEXT"] if is_win else []) + ["PIP_*", "PKG_CONFIG", "PKG_CONFIG_PATH", "PKG_CONFIG_SYSROOT_DIR"] + (["PROCESSOR_ARCHITECTURE"] if is_win else [])