{"id":"9e44a12994b0427d","repo":"pytest-dev/pytest","slug":"invalid-lineno-lineno-r-e","errorCode":null,"errorMessage":"invalid lineno {lineno_!r}: {e}","messagePattern":"invalid lineno (.+?): (.+?)","errorType":"exception","errorClass":"UsageError","httpStatus":null,"severity":"error","filePath":"src/_pytest/config/__init__.py","lineNumber":2311,"sourceCode":"    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)\n    if module and escape:\n        module = re.escape(module) + r\"\\Z\"\n    if lineno_:\n        try:\n            lineno = int(lineno_)\n            if lineno < 0:\n                raise ValueError(\"number is negative\")\n        except ValueError as e:\n            raise UsageError(\n                error_template.format(error=f\"invalid lineno {lineno_!r}: {e}\")\n            ) from None\n    else:\n        lineno = 0\n    try:\n        re.compile(message)\n        re.compile(module)\n    except re.error as e:\n        raise UsageError(\n            error_template.format(error=f\"Invalid regex {e.pattern!r}: {e}\")\n        ) from None\n    return action, message, category, module, lineno\n\n\ndef _resolve_warning_category(category: str) -> type[Warning]:\n    \"\"\"\n    Copied from warnings._getcategory, but changed so it lets exceptions (specially ImportErrors)\n    propagate so we can get access to their tracebacks (#9218).","sourceCodeStart":2293,"sourceCodeEnd":2329,"githubUrl":"https://github.com/pytest-dev/pytest/blob/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/config/__init__.py#L2293-L2329","documentation":"Pytest raises this UsageError when the line-number (5th) field of a warning filter spec is not a valid non-negative integer. The offending lineno string and the underlying ValueError (including the 'number is negative' inner message) are shown. This is the user-facing wrapper around the ValueError from int() parsing or the negativity check.","triggerScenarios":"A filter like 'ignore::DeprecationWarning::mymod:abc' (non-numeric lineno) or 'ignore::DeprecationWarning::mymod:-3' (negative). The int(lineno_) call raises ValueError, which is caught and reformatted as this UsageError.","commonSituations":"Typos in the lineno field; accidentally placing a module name or message in the lineno slot due to mis-counted colons; copied filter strings from a source that used a different field delimiter.","solutions":["Remove the lineno field entirely if you don't need line-scoped filtering (leave it empty).","Provide a valid non-negative integer (0 means any line).","Count your colons — exactly 4 separators for 5 fields: action:message:category:module:lineno."],"exampleFix":"# before (non-numeric lineno)\npytest -W 'ignore::DeprecationWarning::mymod:line42'\n\n# after\npytest -W 'ignore::DeprecationWarning::mymod:42'","handlingStrategy":"validation","validationCode":"def parse_lineno(field: str) -> int:\n    field = field.strip()\n    if not field:\n        return 0\n    try:\n        n = int(field)\n    except ValueError:\n        raise ValueError(f'invalid lineno {field!r}: not an integer')\n    if n < 0:\n        raise ValueError(f'invalid lineno {field!r}: negative')\n    return n","typeGuard":"def is_valid_lineno_str(value: str) -> bool:\n    try:\n        n = int(value)\n    except ValueError:\n        return False\n    return n >= 0","tryCatchPattern":null,"preventionTips":["Leave the lineno field empty if unused.","When templating filters, coerce the lineno through int() and check >= 0."],"tags":["pytest","config","warnings","filterwarnings","validation"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}