Skip to content

Commit e17dda1

Browse files
committed
Always pass FORCE_COLOR & NO_COLOR to the environment
The environment variables `FORCE_COLOR` and `NO_COLOR`are a popular way to force or disable color output. An example usage is pytest being run under a CI system.
1 parent 383845a commit e17dda1

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

docs/changelog/3171.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Always pass ``FORCE_COLOR`` and ``NO_COLOR`` to the environment

src/tox/tox_env/api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ def _default_pass_env(self) -> list[str]:
219219
"LD_LIBRARY_PATH", # location of libs
220220
"LDFLAGS", # linker flags
221221
"HOME", # needed for `os.path.expanduser()` on non-Windows systems
222+
"FORCE_COLOR", # force color output
223+
"NO_COLOR", # disable color output
222224
]
223225
if sys.stdout.isatty(): # if we're on a interactive shell pass on the TERM
224226
env.append("TERM")

tests/session/cmd/test_show_config.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,11 @@ def test_pass_env_config_default(tox_project: ToxProjectCreator, stdout_is_atty:
123123
+ (["APPDATA"] if is_win else [])
124124
+ ["CC", "CCSHARED", "CFLAGS"]
125125
+ (["COMSPEC"] if is_win else [])
126-
+ ["CPPFLAGS", "CURL_CA_BUNDLE", "CXX", "HOME", "LANG", "LANGUAGE", "LDFLAGS", "LD_LIBRARY_PATH"]
127-
+ (["MSYSTEM", "NUMBER_OF_PROCESSORS", "PATHEXT"] if is_win else [])
126+
+ ["CPPFLAGS", "CURL_CA_BUNDLE", "CXX", "FORCE_COLOR", "HOME", "LANG"]
127+
+ ["LANGUAGE", "LDFLAGS", "LD_LIBRARY_PATH"]
128+
+ (["MSYSTEM"] if is_win else [])
129+
+ ["NO_COLOR"]
130+
+ (["NUMBER_OF_PROCESSORS", "PATHEXT"] if is_win else [])
128131
+ ["PIP_*", "PKG_CONFIG", "PKG_CONFIG_PATH", "PKG_CONFIG_SYSROOT_DIR"]
129132
+ (["PROCESSOR_ARCHITECTURE"] if is_win else [])
130133
+ (["PROGRAMDATA"] if is_win else [])

0 commit comments

Comments
 (0)