{"id":"a29daba0c7e7795a","repo":"pytest-dev/pytest","slug":"line-fnline-r-not-found-in-output","errorCode":null,"errorMessage":"line {fnline!r} not found in output","messagePattern":"line (.+?) not found in output","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/_pytest/pytester.py","lineNumber":1634,"sourceCode":"        for line in lines2:\n            for x in self.lines:\n                if line == x or match_func(x, line):\n                    self._log(\"matched: \", repr(line))\n                    break\n            else:\n                msg = f\"line {line!r} not found in output\"\n                self._log(msg)\n                self._fail(msg)\n\n    def get_lines_after(self, fnline: str) -> Sequence[str]:\n        \"\"\"Return all lines following the given line in the text.\n\n        The given line can contain glob wildcards.\n        \"\"\"\n        for i, line in enumerate(self.lines):\n            if fnline == line or fnmatch(line, fnline):\n                return self.lines[i + 1 :]\n        raise ValueError(f\"line {fnline!r} not found in output\")\n\n    def _log(self, *args) -> None:\n        self._log_output.append(\" \".join(str(x) for x in args))\n\n    @property\n    def _log_text(self) -> str:\n        return \"\\n\".join(self._log_output)\n\n    def fnmatch_lines(\n        self, lines2: Sequence[str], *, consecutive: bool = False\n    ) -> None:\n        \"\"\"Check lines exist in the output (using :func:`python:fnmatch.fnmatch`).\n\n        The argument is a list of lines which have to match and can use glob\n        wildcards.  If they do not match a pytest.fail() is called.  The\n        matches and non-matches are also shown as part of the error message.\n\n        :param lines2: String patterns to match.","sourceCodeStart":1616,"sourceCodeEnd":1652,"githubUrl":"https://github.com/pytest-dev/pytest/blob/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/pytester.py#L1616-L1652","documentation":"Raised by RunResult.get_lines_after when the requested fnline (which may contain glob wildcards, matched via fnmatch) does not appear anywhere in the captured output lines. get_lines_after returns all lines following the first match, so a total absence of a match is a hard failure.","triggerScenarios":"Calling result.get_lines_after('some marker string') where that exact string (or wildcard pattern) is not present in stdout/stderr captured from the pytest run.","commonSituations":"Asserting on output that was suppressed (e.g. by -q or a custom reporter); a typo or stale expectation after changing the code under test; the line was emitted to a different stream than the one being searched; glob pattern uses incorrect wildcards.","solutions":["Inspect result.stdout.str() to confirm the expected line and its exact formatting.","Use fnmatch wildcards (e.g. '*marker*') if whitespace/details vary.","Search the correct stream (stdout vs stderr) — get_lines_after operates on self.lines.","Update the expected line to match the current output of the code under test."],"exampleFix":"// before\nlines = result.get_lines_after(\"STARTED processing\")\n// after\nlines = result.get_lines_after(\"*STARTED*processing*\")","handlingStrategy":"validation","validationCode":"from fnmatch import fnmatch\n\ndef line_exists(result, pattern: str) -> bool:\n    return any(fnmatch(line, pattern) for line in result.stdout.lines)\n\nif not line_exists(result, \"*marker*\"):\n    raise AssertionError(f\"marker not found; output:\\n{result.stdout.str()}\")\nlines = result.get_lines_after(\"*marker*\")","typeGuard":null,"tryCatchPattern":"try:\n    lines = result.get_lines_after(pattern)\nexcept ValueError:\n    print(result.stdout.str())\n    raise","preventionTips":["Use fnmatch wildcards to tolerate minor formatting differences.","Inspect stdout before asserting on specific lines.","Keep expected lines in sync with code changes."],"tags":["pytester","output-parsing","assertion"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}