{"id":"57637125a5a0acd8","repo":"pytest-dev/pytest","slug":"invalid-truth-value-val-r","errorCode":null,"errorMessage":"invalid truth value {val!r}","messagePattern":"invalid truth value (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/_pytest/config/__init__.py","lineNumber":2242,"sourceCode":"    return tw\n\n\ndef _strtobool(val: str) -> bool:\n    \"\"\"Convert a string representation of truth to True or False.\n\n    True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values\n    are 'n', 'no', 'f', 'false', 'off', and '0'.  Raises ValueError if\n    'val' is anything else.\n\n    .. note:: Copied from distutils.util.\n    \"\"\"\n    val = val.lower()\n    if val in (\"y\", \"yes\", \"t\", \"true\", \"on\", \"1\"):\n        return True\n    elif val in (\"n\", \"no\", \"f\", \"false\", \"off\", \"0\"):\n        return False\n    else:\n        raise ValueError(f\"invalid truth value {val!r}\")\n\n\n@lru_cache(maxsize=50)\ndef parse_warning_filter(\n    arg: str, *, escape: bool\n) -> tuple[warnings._ActionKind, str, type[Warning], str, int]:\n    \"\"\"Parse a warnings filter string.\n\n    This is copied from warnings._setoption with the following changes:\n\n    * Does not apply the filter.\n    * Escaping is optional.\n    * Raises UsageError so we get nice error messages on failure.\n    \"\"\"\n    __tracebackhide__ = True\n    error_template = dedent(\n        f\"\"\"\\\n        while parsing the following warning configuration:","sourceCodeStart":2224,"sourceCodeEnd":2260,"githubUrl":"https://github.com/pytest-dev/pytest/blob/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/config/__init__.py#L2224-L2260","documentation":"Raised by _strtobool (config/__init__.py:2227-2242), the distutils-derived truthiness parser used to coerce INI bool values. Only the lowercase tokens y/yes/t/true/on/1 (True) and n/no/f/false/off/0 (False) are accepted; anything else raises ValueError naming the bad token. Used by the 'bool' branch of _getini_ini for INI-mode bool options.","triggerScenarios":"Setting a bool ini option (in pytest.ini or pyproject.toml ini_options read in ini mode) to a string outside the accepted set, e.g. addopts = enable, x = 2, or x = YEP.","commonSituations":"Free-form yes/no variants (\"yep\",\"disable\",\"enabled\"); uppercase tokens are fine after .lower() but mixed nonsense fails; non-numeric junk passed as a bool; misconfigured CI config templates.","solutions":["Use one of the accepted tokens: yes/no, true/false, on/off, y/n, t/f, 1/0 (case-insensitive).","For pyproject.toml, prefer a native TOML boolean (true/false) which bypasses _strtobool entirely.","Strip stray whitespace/quotes from the ini value."],"exampleFix":"# before (pytest.ini)\n[pytest]\naddopts = enable\n\n# after\naddopts = true","handlingStrategy":"validation","validationCode":"TRUTHY = {'y','yes','t','true','on','1'}\nFALSY = {'n','no','f','false','off','0'}\ndef parse_bool(token: str) -> bool:\n    t = token.strip().lower()\n    if t in TRUTHY: return True\n    if t in FALSY: return False\n    raise ValueError(f'invalid truth value {t!r}')","typeGuard":"def is_valid_truth_token(token: str) -> bool:\n    return token.strip().lower() in {'y','yes','t','true','on','1','n','no','f','false','off','0'}","tryCatchPattern":"try:\n    val = config.getini(name)\nexcept ValueError:\n    # normalize the ini bool token to true/false and reload","preventionTips":["Use only the accepted bool tokens in INI files.","Prefer native TOML booleans (true/false) in pyproject.toml.","Trim stray whitespace/quotes from ini values."],"tags":["config","ini","bool","strtobool","invalid-value","pytest"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}