{"id":"3f3b8dd8e70c10fa","repo":"pytest-dev/pytest","slug":"unrecognized-runpytest-option-self-method","errorCode":null,"errorMessage":"Unrecognized runpytest option: {self._method}","messagePattern":"Unrecognized runpytest option: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/_pytest/pytester.py","lineNumber":1219,"sourceCode":"            sys.stdout.write(out)\n            sys.stderr.write(err)\n\n        assert reprec.ret is not None\n        res = RunResult(\n            reprec.ret, out.splitlines(), err.splitlines(), instant.elapsed().seconds\n        )\n        res.reprec = reprec  # type: ignore\n        return res\n\n    def runpytest(self, *args: str | os.PathLike[str], **kwargs: Any) -> RunResult:\n        \"\"\"Run pytest inline or in a subprocess, depending on the command line\n        option \"--runpytest\" and return a :py:class:`~pytest.RunResult`.\"\"\"\n        new_args = self._ensure_basetemp(args)\n        if self._method == \"inprocess\":\n            return self.runpytest_inprocess(*new_args, **kwargs)\n        elif self._method == \"subprocess\":\n            return self.runpytest_subprocess(*new_args, **kwargs)\n        raise RuntimeError(f\"Unrecognized runpytest option: {self._method}\")\n\n    def _ensure_basetemp(\n        self, args: Sequence[str | os.PathLike[str]]\n    ) -> list[str | os.PathLike[str]]:\n        new_args = list(args)\n        for x in new_args:\n            if str(x).startswith(\"--basetemp\"):\n                break\n        else:\n            new_args.append(\n                \"--basetemp={}\".format(self.path.parent.joinpath(\"basetemp\"))\n            )\n        return new_args\n\n    def parseconfig(self, *args: str | os.PathLike[str]) -> Config:\n        \"\"\"Return a new pytest :class:`pytest.Config` instance from given\n        commandline args.\n","sourceCodeStart":1201,"sourceCodeEnd":1237,"githubUrl":"https://github.com/pytest-dev/pytest/blob/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/pytester.py#L1201-L1237","documentation":"Raised by Pytester.runpytest when self._method is neither 'inprocess' nor 'subprocess'. The _method is normally set by the Pytester factory based on the --runpytest command-line option or defaults to 'inprocess'. Seeing this indicates the internal method field was set to an unexpected value, almost always via a custom/monkeypatched Pytester or a bug in plugin code that constructs one.","triggerScenarios":"Manually constructing a Pytester and setting _method to a typo or unsupported string; a third-party fixture that wraps Pytester and sets an invalid method; a stale plugin incompatible with the installed pytest version.","commonSituations":"Plugin upgrades where the set of valid methods changed; monkeypatching _method in a test; a custom pytester subclass that overrides construction.","solutions":["Do not set _method manually; let the fixture decide based on --runpytest.","Use only 'inprocess' or 'subprocess' as the method value.","Pass the --runpytest=inprocess|subprocess command-line option instead of poking internals.","Update or remove the third-party plugin that sets an unsupported method."],"exampleFix":"// before\npytester._method = \"inline\"  # invalid\npytester.runpytest()\n// after\npytester._method = \"inprocess\"\npytester.runpytest()","handlingStrategy":"validation","validationCode":"VALID_METHODS = {\"inprocess\", \"subprocess\"}\nassert pytester._method in VALID_METHODS, f\"bad method: {pytester._method}\"\npytester.runpytest()","typeGuard":"def is_valid_method(m: object) -> bool:\n    return m in (\"inprocess\", \"subprocess\")","tryCatchPattern":null,"preventionTips":["Never set _method to anything but 'inprocess' or 'subprocess'.","Prefer the --runpytest command-line option to set the method.","Avoid subclassing/monkeypatching Pytester internals."],"tags":["pytester","internal","configuration"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}