{"id":"a2355e4ed33384c8","repo":"pytest-dev/pytest","slug":"while-parsing-the-following-warning-configuration","errorCode":null,"errorMessage":"while parsing the following warning configuration:\n\n  {arg}\n\nThis error occurred:\n\n{error}","messagePattern":"while parsing the following warning configuration:\n\n  (.+?)\n\nThis error occurred:\n\n(.+?)","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/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/config/__init__.py#L2266-L2302","documentation":"Raised by parse_warning_filter (config/__init__.py:2246-2284) when a -W / filterwarnings entry splits into more than 5 colon-separated fields. The expected shape is action:message:category:module:lineno (at most 5 fields); excess colons (e.g. a module path with '::' or a message containing ':') push the count over and the entry is reported verbatim in a UsageError.","triggerScenarios":"Passing -W 'default::DeprecationWarning:mypackage::sub' (extra colons) or a filterwarnings entry whose message/module text contains unescaped colons. pytest splits on ':' and counts parts.","commonSituations":"Filter strings copied from Python docs with extra separators; module paths containing '::'; messages with embedded colons; misusing the lineno field by appending trailing segments.","solutions":["Limit the filter to at most 5 colon-separated fields: action:message:category:module:lineno.","Remove extra colons in module paths (use dotted form, e.g. mypackage.sub not mypackage::sub).","If the message must contain a colon, place it in a field that is matched by substring or use a regex via action 'default' carefully — or move the filter into code via warnings.filterwarnings.","Re-read the error block: it echoes the exact failing entry for easy correction."],"exampleFix":"# before\npytest -W 'default::DeprecationWarning:mypkg::sub:extra'\n\n# after\npytest -W 'default::DeprecationWarning:mypkg.sub'","handlingStrategy":"validation","validationCode":"def validate_warning_filter(arg: str):\n    if len(arg.split(':')) > 5:\n        raise ValueError(\n            f'warning filter has {len(arg.split(\":\"))} fields; max 5: '\n            'action:message:category:module:lineno'\n        )\n    return arg","typeGuard":"def is_well_formed_filter(arg: str) -> bool:\n    return len(arg.split(':')) <= 5","tryCatchPattern":"try:\n    pytest.main(['-W', arg])\nexcept Exception:\n    # rewrite the filter to <=5 fields and retry","preventionTips":["Keep -W/filterwarnings entries to at most 5 colon-separated fields.","Use dotted module paths (pkg.sub) to avoid stray '::'.","For messages containing colons, use warnings.filterwarnings in code instead."],"tags":["config","warnings","filterwarnings","cli","invalid-argument","pytest"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}