{"record":{"id":"0cff68b5467a1e0a","repo":"pytest-dev/pytest","slug":"too-many-fields-len-parts-expected-at-most-5","errorCode":null,"errorMessage":"Too many fields ({len(parts)}), expected at most 5 separated by colons:\n\n  action:message:category:module:line\n\nFor more information please consult: {doc_url}","messagePattern":"Too many fields \\((.+?)\\), expected at most 5 separated by colons:\n\n  action:message:category:module:line\n\nFor more information please consult: (.+?)","errorType":"exception","errorClass":"UsageError","httpStatus":null,"severity":"error","filePath":"src/_pytest/config/__init__.py","lineNumber":2284,"sourceCode":"        {{error}}\n        \"\"\"\n    )\n\n    parts = arg.split(\":\")\n    if len(parts) > 5:\n        doc_url = (\n            \"https://docs.python.org/3/library/warnings.html#describing-warning-filters\"\n        )\n        error = dedent(\n            f\"\"\"\\\n            Too many fields ({len(parts)}), expected at most 5 separated by colons:\n\n              action:message:category:module:line\n\n            For more information please consult: {doc_url}\n            \"\"\"\n        )\n        raise UsageError(error_template.format(error=error))\n\n    while len(parts) < 5:\n        parts.append(\"\")\n    action_, message, category_, module, lineno_ = (s.strip() for s in parts)\n    try:\n        action: warnings._ActionKind = warnings._getaction(action_)  # type: ignore[attr-defined]\n    except warnings._OptionError as e:\n        raise UsageError(error_template.format(error=str(e))) from None\n    try:\n        category: type[Warning] = _resolve_warning_category(category_)\n    except ImportError:\n        raise\n    except Exception:\n        exc_info = ExceptionInfo.from_current()\n        exception_text = exc_info.getrepr(style=\"native\")\n        raise UsageError(error_template.format(error=exception_text)) from None\n    if message and escape:\n        message = re.escape(message)","sourceCodeStart":2266,"sourceCodeEnd":2302,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/config/__init__.py#L2266-L2302","documentation":"Raised by parse_warning_filter() when a warning filter string has more than 5 colon-separated fields. Warning filters use the format action:message:category:module:line, which is exactly 5 fields max. The error is wrapped in a pytest UsageError with a helpful template and a link to the Python warnings documentation.","triggerScenarios":"Providing a filterwarnings value or -W flag with more than 5 colon-delimited segments. Example: filterwarnings = [\"ignore::DeprecationWarning:mymodule:0:extra\"]. The `len(parts) > 5` check after arg.split(':') triggers.","commonSituations":"Misunderstanding the warning filter format and adding extra segments. Copying a malformed filter string from documentation or a Stack Overflow answer. Accidentally including a colon inside a module path or message regex (colons are field delimiters).","solutions":["Count colon-separated fields and reduce to at most 5: action:message:category:module:line","If you need colons inside message or module regex, they cannot be used — restructure the filter","Consult https://docs.python.org/3/library/warnings.html#describing-warning-filters for the format"],"exampleFix":"# pyproject.toml — before\n[tool.pytest.ini_options]\nfilterwarnings = [\"ignore::DeprecationWarning:mymodule:0:extra\"]\n\n# after\n[tool.pytest.ini_options]\nfilterwarnings = [\"ignore::DeprecationWarning:mymodule:0\"]","handlingStrategy":"validation","validationCode":"def validate_warning_filter(arg: str) -> bool:\n    parts = arg.split(':')\n    return len(parts) <= 5","typeGuard":null,"tryCatchPattern":"from pytest import UsageError\ntry:\n    parse_warning_filter(arg, escape=True)\nexcept UsageError as e:\n    print(f\"Invalid warning filter: {e}\")","preventionTips":["Count colon-separated fields — max is 5: action:message:category:module:line","Avoid colons inside message or module regex (they are delimiters)","Test filter strings in isolation before adding to config"],"tags":["pytest","config","warnings","filterwarnings","string-parsing"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}