{"record":{"id":"91cab732c8fd9b15","repo":"pytest-dev/pytest","slug":"config-is-not-a-valid-argument-for-from-parent","errorCode":null,"errorMessage":"config is not a valid argument for from_parent","messagePattern":"config is not a valid argument for from_parent","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/_pytest/nodes.py","lineNumber":222,"sourceCode":"        #: own use.\n        self.stash: Stash = Stash()\n        # Deprecated alias. Was never public. Can be removed in a few releases.\n        self._store = self.stash\n\n    @classmethod\n    def from_parent(cls, parent: Node, **kw) -> Self:\n        \"\"\"Public constructor for Nodes.\n\n        This indirection got introduced in order to enable removing\n        the fragile logic from the node constructors.\n\n        Subclasses can use ``super().from_parent(...)`` when overriding the\n        construction.\n\n        :param parent: The parent node of this Node.\n        \"\"\"\n        if \"config\" in kw:\n            raise TypeError(\"config is not a valid argument for from_parent\")\n        if \"session\" in kw:\n            raise TypeError(\"session is not a valid argument for from_parent\")\n        return cls._create(parent=parent, **kw)\n\n    @property\n    def ihook(self) -> pluggy.HookRelay:\n        \"\"\"Path-sensitive hook proxy used to call pytest hooks.\"\"\"\n        return self.session.gethookproxy(self.path)\n\n    def __repr__(self) -> str:\n        return \"<{} {}>\".format(self.__class__.__name__, getattr(self, \"name\", None))\n\n    def warn(self, warning: Warning) -> None:\n        \"\"\"Issue a warning for this Node.\n\n        Warnings will be displayed after the test session, unless explicitly suppressed.\n\n        :param Warning warning:","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/nodes.py#L204-L240","documentation":"Raised by Node.from_parent when 'config' appears in the kwargs. from_parent deliberately excludes config and session from its accepted kwargs (lines 221-224) because config is always inherited from the parent; passing it would create inconsistency. The guard fails fast with a TypeError before delegating to _create.","triggerScenarios":"Node.from_parent(parent, config=cfg, ...); passing config= as a kwarg to a Node subclass's from_parent; copying constructor kwargs into from_parent calls.","commonSituations":"Migrating from direct Node(...) construction to from_parent without stripping config; plugin code that threads config through kwargs.","solutions":["Remove config= from the from_parent call; config is inherited from parent.","If you need a specific config, ensure the parent node carries it.","Audit from_parent call sites for stray config/session kwargs."],"exampleFix":"// before\nitem = MyItem.from_parent(parent=collector, name='x', config=config)\n// after\nitem = MyItem.from_parent(parent=collector, name='x')","handlingStrategy":"type-guard","validationCode":"kw.pop('config', None)  # never pass config to from_parent","typeGuard":"def _from_parent_kw_clean(kw) -> bool:\n    return 'config' not in kw and 'session' not in kw","tryCatchPattern":null,"preventionTips":["Strip config/session from kwargs before calling from_parent.","Remember from_parent inherits config and session from the parent."],"tags":["pytest","nodes","typeerror","internal-api"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}