{"id":"419b1850df40473b","repo":"pytest-dev/pytest","slug":"redirected-stdin-is-pseudofile-has-no-seek-int","errorCode":null,"errorMessage":"redirected stdin is pseudofile, has no seek(int)","messagePattern":"redirected stdin is pseudofile, has no seek\\(int\\)","errorType":"exception","errorClass":"UnsupportedOperation","httpStatus":null,"severity":"warning","filePath":"src/_pytest/capture.py","lineNumber":262,"sourceCode":"        return self\n\n    def fileno(self) -> int:\n        raise UnsupportedOperation(\"redirected stdin is pseudofile, has no fileno()\")\n\n    def flush(self) -> None:\n        raise UnsupportedOperation(\"redirected stdin is pseudofile, has no flush()\")\n\n    def isatty(self) -> bool:\n        return False\n\n    def close(self) -> None:\n        pass\n\n    def readable(self) -> bool:\n        return False\n\n    def seek(self, offset: int, whence: int = 0) -> int:\n        raise UnsupportedOperation(\"redirected stdin is pseudofile, has no seek(int)\")\n\n    def seekable(self) -> bool:\n        return False\n\n    def tell(self) -> int:\n        raise UnsupportedOperation(\"redirected stdin is pseudofile, has no tell()\")\n\n    def truncate(self, size: int | None = None) -> int:\n        raise UnsupportedOperation(\"cannot truncate stdin\")\n\n    def write(self, data: str) -> int:\n        raise UnsupportedOperation(\"cannot write to stdin\")\n\n    def writelines(self, lines: Iterable[str]) -> None:\n        raise UnsupportedOperation(\"Cannot write to stdin\")\n\n    def writable(self) -> bool:\n        return False","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/pytest-dev/pytest/blob/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/capture.py#L244-L280","documentation":"DontReadFromInput.seek() raises UnsupportedOperation because the captured stdin pseudo-file is a sequential in-memory stream that does not support repositioning. seekable() already returns False.","triggerScenarios":"In a test under default capture, code calls sys.stdin.seek(offset) — typical of parsers that try to rewind a stream.","commonSituations":"A parser/decoder that rewinds stdin on a lookahead; generic stream-handling utilities that call seek/tell on any file-like object; replay logic that assumes random access.","solutions":["Run pytest with -s.","Refactor code to buffer the input itself rather than seeking stdin.","Guard seek calls with a seekable() check before invoking seek."],"exampleFix":"// before\n# code: sys.stdin.seek(0)\n// after\n# code: data = sys.stdin.read()  # buffer once, reparse in memory\n#       or check: if sys.stdin.seekable(): sys.stdin.seek(0)","handlingStrategy":"type-guard","validationCode":"def safe_seek(stream, offset, whence=0):\n    if not getattr(stream, 'seekable', lambda: False)():\n        raise UnsupportedOperation('stream is not seekable')\n    return stream.seek(offset, whence)","typeGuard":"def is_seekable(stream) -> bool:\n    return bool(getattr(stream, 'seekable', lambda: False)())","tryCatchPattern":"from io import UnsupportedOperation\ntry:\n    stream.seek(0)\nexcept (OSError, UnsupportedOperation, ValueError):\n    pass  # consume fresh data instead","preventionTips":["Check seekable() before calling seek/tell.","Buffer input yourself rather than rewinding stdin."],"tags":["pytest","capture","stdin","io"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}