{"record":{"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/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/capture.py#L705-L741","documentation":"Raised at the end of _get_multicapture() (src/_pytest/capture.py:723). _CaptureMethod (capture.py:46) is Literal['fd','sys','no','tee-sys']; the four branches at capture.py:713-722 cover them, so any other value hits the trailing ValueError. This is the final defensive raise after the if/elif chain.","triggerScenarios":"Passing an unrecognized value to --capture on the CLI, the `capture` ini option in pyproject.toml/pytest.ini/setup.cfg, or constructing MultiCapture directly via _get_multicapture with a custom string. A typo like --capture=tty-sys or capture = fd,sys reaches capture.py:723.","commonSituations":"Typo in pytest.ini's `addopts = --capture=...`, porting an old config from another runner (nosetests capture names), or a plugin that overrides the capture option with an invalid value.","solutions":["Use one of the four valid values: fd, sys, no, or tee-sys","Check the [pytest] section of pyproject.toml / pytest.ini and the PYTEST_ADDOPTS env var for stray --capture= values","If invoking CaptureManager programmatically, type the variable as Literal['fd','sys','no','tee-sys'] (capture.py:46) so the typo is caught at typecheck time","Remove the override entirely to fall back to the default 'fd'"],"exampleFix":"// before\n# pytest.ini\n[pytest]\naddopts = --capture=tty\n// after\n[pytest]\naddopts = --capture=tee-sys","handlingStrategy":"validation","validationCode":"VALID = {'fd', 'sys', 'no', 'tee-sys'}\nif method not in VALID:\n    raise ValueError(f'capture must be one of {VALID}, got {method!r}')","typeGuard":"from typing import Literal, get_args\nfrom _pytest.capture import _CaptureMethod\n_VALID_CAPTURE = set(get_args(_CaptureMethod))  # {'fd','sys','no','tee-sys'}\ndef is_valid_capture(m: str) -> bool:\n    return m in _VALID_CAPTURE","tryCatchPattern":"try:\n    from _pytest.capture import _get_multicapture\n    cap = _get_multicapture(method)\nexcept ValueError as e:\n    print(f'Bad --capture value: {e}')","preventionTips":["When constructing pytest args programmatically, validate against the Literal get_args(_CaptureMethod)","Audit PYTEST_ADDOPTS and addopts for stray --capture values when CI breaks","Document the four valid values in your project README"],"tags":["capture","config","cli","validation"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}