Skip to content

Commit

Permalink
NO_COLOR follows no-color.org logic instead of tox boolean (#2727)
Browse files Browse the repository at this point in the history
Co-authored-by: ptmcg <ptmcg@austin.rr.com>
  • Loading branch information
gaborbernat and ptmcg committed Dec 15, 2022
1 parent bfd9191 commit 8c0239e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/changelog/2719.feature.rst
@@ -0,0 +1,4 @@
Modified handling of ``NO_COLOR`` environment variable, consistent with
`de facto conventions <https://no-color.org>`_: any non-empty string will enable ``NO_COLOR`` (disable colorized
output); no ``NO_COLOR`` variable or ``NO_COLOR`` with an empty string will disable ``NO_COLOR`` (enable colorized
output) - by :user:`ptmcg`.
2 changes: 1 addition & 1 deletion src/tox/config/cli/parser.py
Expand Up @@ -290,7 +290,7 @@ def add_verbosity_flags(parser: ArgumentParser) -> None:

def add_color_flags(parser: ArgumentParser) -> None:
converter = StrConvert()
if converter.to_bool(os.environ.get("NO_COLOR", "")):
if os.environ.get("NO_COLOR", "") != "":
color = "no"
elif converter.to_bool(os.environ.get("FORCE_COLOR", "")):
color = "yes"
Expand Down
4 changes: 2 additions & 2 deletions tests/config/cli/test_parser.py
Expand Up @@ -28,7 +28,7 @@ def test_parser_const_with_default_none(monkeypatch: MonkeyPatch) -> None:


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

if tox_color in ("yes", "no"):
expected = tox_color == "yes"
elif no_color == "1":
elif bool(no_color):
expected = False
elif force_color == "1":
expected = True
Expand Down

0 comments on commit 8c0239e

Please sign in to comment.