{"record":{"id":"e6162192eb1b3b71","repo":"pytest-dev/pytest","slug":"specifying-plugins-as-objects-is-not-supported-in","errorCode":null,"errorMessage":"Specifying plugins as objects is not supported in pytester subprocess mode; specify by name instead: {plugin}","messagePattern":"Specifying plugins as objects is not supported in pytester subprocess mode; specify by name instead: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/_pytest/pytester.py","lineNumber":1515,"sourceCode":"        ``-p`` command line option.  Additionally ``--basetemp`` is used to put\n        any temporary files and directories in a numbered directory prefixed\n        with \"runpytest-\" to not conflict with the normal numbered pytest\n        location for temporary files and directories.\n\n        :param args:\n            The sequence of arguments to pass to the pytest subprocess.\n        :param timeout:\n            The period in seconds after which to timeout and raise\n            :py:class:`Pytester.TimeoutExpired`.\n        :returns:\n            The result.\n        \"\"\"\n        __tracebackhide__ = True\n        p = make_numbered_dir(root=self.path, prefix=\"runpytest-\", mode=0o700)\n        args = (f\"--basetemp={p}\", *args)\n        for plugin in self.plugins:\n            if not isinstance(plugin, str):\n                raise ValueError(\n                    f\"Specifying plugins as objects is not supported in pytester subprocess mode; \"\n                    f\"specify by name instead: {plugin}\"\n                )\n            args = (\"-p\", plugin, *args)\n        args = self._getpytestargs() + args\n        return self.run(*args, timeout=timeout)\n\n    def spawn_pytest(self, string: str, expect_timeout: float = 10.0) -> pexpect.spawn:\n        \"\"\"Run pytest using pexpect.\n\n        This makes sure to use the right pytest and sets up the temporary\n        directory locations.\n\n        The pexpect child is returned.\n        \"\"\"\n        basetemp = self.path / \"temp-pexpect\"\n        basetemp.mkdir(mode=0o700)\n        invoke = \" \".join(map(str, self._getpytestargs()))","sourceCodeStart":1497,"sourceCodeEnd":1533,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/pytester.py#L1497-L1533","documentation":"Thrown by Pytester.runpytest_subprocess() when any entry in pytester.plugins is not a string. Subprocess mode can only forward plugin names via `-p <name>`; it cannot pickle/ship plugin object instances across process boundaries.","triggerScenarios":"Setting pytester.plugins = [MyPlugin()] (an object) then calling runpytest_subprocess(); writing a test that worked under runpytest_inprocess (which accepts objects) and switching to subprocess mode; appending a plugin module object instead of its dotted name.","commonSituations":"Migrating from inprocess to subprocess for isolation; plugin tests that register a plugin instance by object; helper fixtures that populate plugins list with instances.","solutions":["Pass plugin names (strings) instead of objects: use 'myplugin' or 'mymod.plugin'.","Use runpytest_inprocess() if you must register plugin objects.","Ensure the plugin is importable in the subprocess (installed or on PYTHONPATH)."],"exampleFix":"// before\npytester.plugins = [MyPlugin()]\npytester.runpytest_subprocess()\n// after\npytester.plugins = [\"myplugin\"]  # ensure it's pip-installed or on PYTHONPATH\npytester.runpytest_subprocess()","handlingStrategy":"type-guard","validationCode":"for i, p in enumerate(pytester.plugins):\n    if not isinstance(p, str):\n        pytest.fail(f'plugin {i} is an object, not a name: {p!r}')\npytester.runpytest_subprocess()","typeGuard":"def all_plugins_named(plugins: list) -> bool:\n    return all(isinstance(p, str) for p in plugins)","tryCatchPattern":null,"preventionTips":["Pass plugin names (strings) for subprocess mode.","Use runpytest_inprocess() when you need plugin objects.","Ensure named plugins are importable in the subprocess environment."],"tags":["pytester","subprocess","plugins","serialization"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}