{"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":"validation","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/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/nodes.py#L204-L240","documentation":"Node.from_parent intentionally rejects a `config` keyword. config and session are always inherited from the parent in from_parent, so passing them would create inconsistency. The guard forces correct usage of the public constructor.","triggerScenarios":"Calling MyNode.from_parent(parent, config=cfg, ...) or passing config via **kw to from_parent. Plugin code migrated from the old constructor pattern often leaks config through.","commonSituations":"Older pytest plugins/tutorials that passed config= to constructors; copy-paste from __init__ into a from_parent override.","solutions":["Remove the config kwarg from the from_parent call; config is derived from the parent","If you truly need a different config, call the constructor (_create / __init__) directly instead of from_parent"],"exampleFix":"// before\nitem = MyItem.from_parent(parent, name=n, config=cfg)\n// after\nitem = MyItem.from_parent(parent, name=n)","handlingStrategy":"validation","validationCode":"def safe_from_parent(cls, parent, **kw):\n    kw.pop('config', None)  # never forward config\n    return cls.from_parent(parent, **kw)","typeGuard":"def kwargs_have_no_config(kw) -> bool:\n    return 'config' not in kw","tryCatchPattern":null,"preventionTips":["Never forward config through from_parent; it is inherited","Audit from_parent overrides for stray **kwargs leaking config"],"tags":["nodes","plugin-api","pytest","from-parent"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}