{"id":"93b11c038f82588a","repo":"pytest-dev/pytest","slug":"config-or-parent-must-be-provided","errorCode":null,"errorMessage":"config or parent must be provided","messagePattern":"config or parent must be provided","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/_pytest/nodes.py","lineNumber":168,"sourceCode":"        parent: Node | None = None,\n        config: Config | None = None,\n        session: Session | None = None,\n        fspath: None = None,\n        path: Path | None = None,\n        nodeid: str | None = None,\n    ) -> None:\n        #: A unique name within the scope of the parent node.\n        self.name: str = name\n\n        #: The parent collector node.\n        self.parent = parent\n\n        if config:\n            #: The pytest config object.\n            self.config: Config = config\n        else:\n            if not parent:\n                raise TypeError(\"config or parent must be provided\")\n            self.config = parent.config\n\n        if session:\n            #: The pytest session this node is part of.\n            self.session: Session = session\n        else:\n            if not parent:\n                raise TypeError(\"session or parent must be provided\")\n            self.session = parent.session\n\n        if path is None:\n            assert parent is not None\n            path = parent.path\n        #: Filesystem path where this node was collected from.\n        self.path: pathlib.Path = path\n\n        # The explicit annotation is to avoid publicly exposing NodeKeywords.\n        #: Keywords/markers collected from all scopes.","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/pytest-dev/pytest/blob/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/nodes.py#L150-L186","documentation":"Node.__init__ requires either a parent node (config is then inherited from parent.config) or an explicit config object. Constructing a Node with neither makes the node unusable, so pytest raises TypeError. Hits plugin authors subclassing Node/Collector/Item directly.","triggerScenarios":"Instantiating a Node subclass like MyNode('name') with no parent and no config keyword. Most common when a plugin bypasses Node.from_parent and calls the constructor manually.","commonSituations":"Custom collector/item plugins that construct nodes without forwarding the parent; mis-copied constructor calls; refactor that dropped the parent argument.","solutions":["Pass a parent node: MyNode(name, parent=parent_node)","If root-level, pass both config and session explicitly along with nodeid"],"exampleFix":"// before\nnode = MyNode('test_x')\n// after\nnode = MyNode('test_x', parent=parent_node)","handlingStrategy":"validation","validationCode":"def make_node(cls, name, *, parent=None, config=None, **kw):\n    if parent is None and config is None:\n        raise TypeError(\"provide parent or config\")\n    return cls(name, parent=parent, config=config, **kw)","typeGuard":"def has_parent_or_config(parent, config) -> bool:\n    return parent is not None or config is not None","tryCatchPattern":null,"preventionTips":["Prefer Node.from_parent(parent, ...) over the raw constructor for custom nodes","Always forward parent from the calling hook"],"tags":["nodes","plugin-api","pytest","constructor"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}