tox icon indicating copy to clipboard operation
tox copied to clipboard

Tox crashes with `FORCE_COLOR` is some arbitrary string

Open WhyNotHugo opened this issue 4 months ago • 2 comments

Issue

Tox expects FORCE_COLOR to specific be one of yes, true or 0 in order to be enabled.

From https://force-color.org/:

When this variable is present and not an empty string (regardless of its value), it should force the addition of ANSI color.

Environment

Tox 4.27.0

Output of running tox

With FORCE_COLOR=not an empty string:

Traceback (most recent call last):
  File "/usr/bin/tox", line 8, in <module>
    sys.exit(run())
             ^^^^^
  File "/usr/lib/python3.12/site-packages/tox/run.py", line 19, in run
    result = main(sys.argv[1:] if args is None else args)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/tox/run.py", line 38, in main
    state = setup_state(args)
            ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/tox/run.py", line 52, in setup_state
    options = get_options(*args)
              ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/tox/config/cli/parse.py", line 36, in get_options
    guess_verbosity, log_handler, source = _get_base(args)
                                           ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/tox/config/cli/parse.py", line 45, in _get_base
    tox_parser = ToxParser.base()
                 ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/tox/config/cli/parser.py", line 223, in base
    return cls(add_help=False, root=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/tox/config/cli/parser.py", line 146, in __init__
    self._add_base_options()
  File "/usr/lib/python3.12/site-packages/tox/config/cli/parser.py", line 237, in _add_base_options
    add_core_arguments(self)
  File "/usr/lib/python3.12/site-packages/tox/config/cli/parser.py", line 317, in add_core_arguments
    add_color_flags(parser)
  File "/usr/lib/python3.12/site-packages/tox/config/cli/parser.py", line 290, in add_color_flags
    elif converter.to_bool(os.environ.get("FORCE_COLOR", "")):
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/tox/config/loader/str_convert.py", line 130, in to_bool
    raise TypeError(msg)
TypeError: value 'not an empty string' cannot be transformed to bool, valid: , 0, 1, false, no, off, on, true, yes

Additional notes

Tox should merely check whether the variable is set, and not expect a family or specifically chosen strings.

WhyNotHugo avatar Aug 09 '25 09:08 WhyNotHugo

Agreed. @gaborbernat if you also agree to support what the site suggests, I'd like to look into this.

jugmac00 avatar Aug 11 '25 07:08 jugmac00

Go ahead.

gaborbernat avatar Aug 11 '25 14:08 gaborbernat