Skip to content

Follow recommendations for FORCE_COLOR #3584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog/3579.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
When the ``FORCE_COLOR`` variable is present and not an empty string, it forces ANSI color to be set.
Previously, only ``yes``, ``true`` or ``0`` were valid values. - by :user:`jugmac00`
4 changes: 1 addition & 3 deletions src/tox/config/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

from colorama import Fore

from tox.config.loader.str_convert import StrConvert
from tox.plugin import NAME
from tox.util.ci import is_ci

Expand Down Expand Up @@ -357,10 +356,9 @@ def add_verbosity_flags(parser: ArgumentParser) -> None:


def add_color_flags(parser: ArgumentParser) -> None:
converter = StrConvert()
if os.environ.get("NO_COLOR", ""):
color = "no"
elif converter.to_bool(os.environ.get("FORCE_COLOR", "")):
elif os.environ.get("FORCE_COLOR", ""):
color = "yes"
elif os.environ.get("TERM", "") == "dumb":
color = "no"
Expand Down
6 changes: 3 additions & 3 deletions tests/config/cli/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ 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", "", "\t", " ", "false", "true"])
@pytest.mark.parametrize("force_color", [None, "0", "1"])
@pytest.mark.parametrize("force_color", [None, "", "0", "1", "string"])
@pytest.mark.parametrize("tox_color", [None, "bad", "no", "yes"])
@pytest.mark.parametrize("term", [None, "xterm", "dumb"])
def test_parser_color( # noqa: PLR0913
def test_color( # noqa: PLR0913
monkeypatch: MonkeyPatch,
mocker: MockerFixture,
no_color: str | None,
Expand All @@ -62,7 +62,7 @@ def test_parser_color( # noqa: PLR0913
expected = tox_color == "yes"
elif bool(no_color):
expected = False
elif force_color == "1":
elif force_color in {"0", "1", "string"}:
expected = True
elif term == "dumb":
expected = False
Expand Down
Loading