Skip to content

Commit 8c0239e

Browse files
gaborbernatptmcg
andauthored
NO_COLOR follows no-color.org logic instead of tox boolean (#2727)
Co-authored-by: ptmcg <[email protected]>
1 parent bfd9191 commit 8c0239e

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

docs/changelog/2719.feature.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Modified handling of ``NO_COLOR`` environment variable, consistent with
2+
`de facto conventions <https://no-color.org>`_: any non-empty string will enable ``NO_COLOR`` (disable colorized
3+
output); no ``NO_COLOR`` variable or ``NO_COLOR`` with an empty string will disable ``NO_COLOR`` (enable colorized
4+
output) - by :user:`ptmcg`.

src/tox/config/cli/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def add_verbosity_flags(parser: ArgumentParser) -> None:
290290

291291
def add_color_flags(parser: ArgumentParser) -> None:
292292
converter = StrConvert()
293-
if converter.to_bool(os.environ.get("NO_COLOR", "")):
293+
if os.environ.get("NO_COLOR", "") != "":
294294
color = "no"
295295
elif converter.to_bool(os.environ.get("FORCE_COLOR", "")):
296296
color = "yes"

tests/config/cli/test_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_parser_const_with_default_none(monkeypatch: MonkeyPatch) -> None:
2828

2929

3030
@pytest.mark.parametrize("is_atty", [True, False])
31-
@pytest.mark.parametrize("no_color", [None, "0", "1"])
31+
@pytest.mark.parametrize("no_color", [None, "0", "1", "", "\t", " ", "false", "true"])
3232
@pytest.mark.parametrize("force_color", [None, "0", "1"])
3333
@pytest.mark.parametrize("tox_color", [None, "bad", "no", "yes"])
3434
@pytest.mark.parametrize("term", [None, "xterm", "dumb"])
@@ -56,7 +56,7 @@ def test_parser_color(
5656

5757
if tox_color in ("yes", "no"):
5858
expected = tox_color == "yes"
59-
elif no_color == "1":
59+
elif bool(no_color):
6060
expected = False
6161
elif force_color == "1":
6262
expected = True

0 commit comments

Comments
 (0)