{"id":"8fee4b32363a3774","repo":"pytest-dev/pytest","slug":"unknown-capturing-method-method-r","errorCode":null,"errorMessage":"unknown capturing method: {method!r}","messagePattern":"unknown capturing method: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/_pytest/capture.py","lineNumber":723,"sourceCode":"    def readouterr(self) -> CaptureResult[AnyStr]:\n        out = self.out.snap() if self.out else \"\"\n        err = self.err.snap() if self.err else \"\"\n        # TODO: This type error is real, need to fix.\n        return CaptureResult(out, err)  # type: ignore[arg-type]\n\n\ndef _get_multicapture(method: _CaptureMethod) -> MultiCapture[str]:\n    if method == \"fd\":\n        return MultiCapture(in_=FDCapture(0), out=FDCapture(1), err=FDCapture(2))\n    elif method == \"sys\":\n        return MultiCapture(in_=SysCapture(0), out=SysCapture(1), err=SysCapture(2))\n    elif method == \"no\":\n        return MultiCapture(in_=None, out=None, err=None)\n    elif method == \"tee-sys\":\n        return MultiCapture(\n            in_=None, out=SysCapture(1, tee=True), err=SysCapture(2, tee=True)\n        )\n    raise ValueError(f\"unknown capturing method: {method!r}\")\n\n\n# CaptureManager and CaptureFixture\n\n\nclass CaptureManager:\n    \"\"\"The capture plugin.\n\n    Manages that the appropriate capture method is enabled/disabled during\n    collection and each test phase (setup, call, teardown). After each of\n    those points, the captured output is obtained and attached to the\n    collection/runtest report.\n\n    There are two levels of capture:\n\n    * global: enabled by default and can be suppressed by the ``-s``\n      option. This is always enabled/disabled during collection and each test\n      phase.","sourceCodeStart":705,"sourceCodeEnd":741,"githubUrl":"https://github.com/pytest-dev/pytest/blob/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/capture.py#L705-L741","documentation":"Raised by _get_multicapture (capture.py:712-723) when the requested capture method is not one of the supported literals: 'fd', 'sys', 'no', or 'tee-sys'. The method string originates from the -s/--capture CLI option or the capture_manager API, and the function explicitly enumerates every legal value before raising.","triggerScenarios":"Invoking pytest with --capture=XXX where XXX is anything other than fd/sys/no/tee-sys; programmatic configuration that sets capture method to an arbitrary string; a typo such as --capture=FD (case-sensitive) or --capture=system.","commonSituations":"Misspelling the method on the command line; copying an outdated capture name from stale docs; plugins/conftest code that calls capture APIs with a custom method string that was never registered.","solutions":["Use one of the documented methods: --capture=fd (default on POSIX), --capture=sys, -s (equivalent to --capture=no), or --capture=tee-sys.","Check spelling and case — the comparison is exact ('fd' not 'FD').","If selecting programmatically, validate against {'fd','sys','no','tee-sys'} before passing to capture APIs.","Remove any conftest/CLI injection that sets an invalid capture string."],"exampleFix":"# before\npytest --capture=tty\n\n# after\npytest --capture=sys","handlingStrategy":"validation","validationCode":"VALID = {'fd', 'sys', 'no', 'tee-sys'}\ndef set_capture(method: str) -> str:\n    assert method in VALID, f'unknown capture method {method!r}; pick from {VALID}'\n    return method","typeGuard":"def is_valid_capture(method: str) -> bool:\n    return method in {'fd', 'sys', 'no', 'tee-sys'}","tryCatchPattern":"try:\n    pytest.main(['--capture', method])\nexcept ValueError as e:\n    # fall back to a known-good method\n    pytest.main(['--capture', 'sys'])","preventionTips":["Validate capture method against the documented set before invoking pytest.","Prefer the -s shorthand for 'no capture' to avoid typos.","Keep CLI construction in one place to audit capture values."],"tags":["capture","cli","invalid-argument","pytest"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}