[core] Parse the common on/off spellings in boolean env vars

This commit is contained in:
J. Nick Koston
2026-08-22 23:26:10 -05:00
parent f0651e5c9b
commit 8760c72945
2 changed files with 23 additions and 2 deletions
+2 -2
View File
@@ -398,9 +398,9 @@ def get_bool_env(var, default=False):
value = os.getenv(var, default)
if isinstance(value, str):
value = value.lower()
if value in ["1", "true"]:
if value in ("1", "true", "yes", "on", "enable"):
return True
if value in ["0", "false"]:
if value in ("0", "false", "no", "off", "disable"):
return False
return bool(value)
+21
View File
@@ -1108,3 +1108,24 @@ def test_progressbar_enabled_on_pipe_with_dashboard(monkeypatch) -> None:
def test_format_duration(seconds: float, expected: str) -> None:
"""Test that durations are rendered as short human-readable strings."""
assert helpers.format_duration(seconds) == expected
@pytest.mark.parametrize(
("value", "expected"),
[
("yes", True),
("on", True),
("enable", True),
("no", False),
("off", False),
("disable", False),
],
)
def test_get_bool_env_common_spellings(
monkeypatch: pytest.MonkeyPatch, value: str, expected: bool
) -> None:
"""The common on/off spellings parse instead of falling through to
bool(str), which read "off" as enabled (e.g. IDF_CCACHE_ENABLE=off
left ccache on)."""
monkeypatch.setenv("SOME_KNOB", value)
assert helpers.get_bool_env("SOME_KNOB") is expected