{"record":{"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/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/config/__init__.py#L2293-L2329","documentation":"Raised by parse_warning_filter() when the lineno field (5th colon-separated segment) of a warning filter is not a valid non-negative integer. The field is parsed via int() and explicitly checked for negativity. The original ValueError message is included.","triggerScenarios":"Providing a warning filter where the line field is a non-numeric string, a float, or a negative number. Example: filterwarnings = [\"ignore::DeprecationWarning:mymodule:abc\"] or [\"ignore::DeprecationWarning:mymodule:-5\"]. The int(lineno_) call raises ValueError or the negativity check fails.","commonSituations":"Typo in the line number field. Using a float or expression. Copying a filter with an invalid line segment. Forgetting that the line field is 1-indexed and must be non-negative.","solutions":["Set the line field to a non-negative integer or omit it (use empty string)","If you don't need a line filter, leave the field blank: \"ignore::DeprecationWarning:mymodule:\"","Double-check the field is a plain integer string with no decimal point or sign"],"exampleFix":"# pyproject.toml — before\nfilterwarnings = [\"ignore::DeprecationWarning:mymodule:abc\"]\n\n# after\nfilterwarnings = [\"ignore::DeprecationWarning:mymodule:42\"]","handlingStrategy":"validation","validationCode":"def validate_warning_filter_lineno(arg: str) -> bool:\n    parts = arg.split(':')\n    if len(parts) < 5 or not parts[4].strip():\n        return True  # line field absent/empty is valid\n    try:\n        return int(parts[4].strip()) >= 0\n    except ValueError:\n        return False","typeGuard":null,"tryCatchPattern":"from pytest import UsageError\ntry:\n    parse_warning_filter(arg, escape=True)\nexcept UsageError as e:\n    print(f\"Invalid lineno in filter: {e}\")","preventionTips":["Use a non-negative integer or empty string for the line field","Omit the line field entirely if line filtering is not needed","Avoid floats or expressions in the line field"],"tags":["pytest","config","warnings","filterwarnings","lineno"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}