{"record":{"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/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/pytester.py#L1201-L1237","documentation":"Thrown by Pytester.runpytest() when self._method is neither 'inprocess' nor 'subprocess'. The _method attribute is set from the --runpytest command-line option and should always be one of those two; this guard catches corruption or custom Pytester subclasses.","triggerScenarios":"Subclassing Pytester and overriding _method with an invalid value; manually setting pytester._method; a future pytest version changing the valid set while an old plugin patches _method; the --runpytest option receiving an unknown value through a config override.","commonSituations":"Custom test harnesses that wrap Pytester; monkeypatching experiments; version skew between pytest and a plugin that touches _method.","solutions":["Do not set pytester._method manually; rely on the --runpytest={inprocess,subprocess} option.","If subclassing, set _method to one of the two documented values.","Check for plugins or conftest.py code that patches _method."],"exampleFix":"// before\npytester._method = \"custom\"\npytester.runpytest()\n// after\npytester._method = \"subprocess\"\npytester.runpytest()","handlingStrategy":"validation","validationCode":"assert pytester._method in ('inprocess', 'subprocess'), f'bad method: {pytester._method}'\npytester.runpytest()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never set _method manually; use --runpytest option.","Audit plugins/conftest.py for _method patches.","Use runpytest_inprocess()/runpytest_subprocess() directly to avoid dispatch."],"tags":["pytester","runpytest","internal","configuration"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}