{"record":{"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":"exception","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/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/nodes.py#L150-L186","documentation":"Raised by Node.__init__ when neither config nor parent is supplied. The constructor at lines 165-170 falls back to parent.config when config is None, so a missing parent with no config leaves no way to obtain the Config object, which is required for every node. This guards against constructing an orphan node that cannot participate in pytest's config/session graph.","triggerScenarios":"Calling Node(...) or a subclass constructor directly with config=None and parent=None; instantiating a custom Node subclass without routing through from_parent; building a node in a plugin without a parent collector.","commonSituations":"Plugin authors instantiate Item/Collector subclasses manually instead of using from_parent; tests that construct nodes standalone for unit testing without stubbing parent.","solutions":["Construct nodes via Node.from_parent(parent, **kw) which propagates config from the parent.","If constructing standalone, pass an explicit config object.","Pass a real parent node so config is inherited."],"exampleFix":"// before\nnode = MyItem(name='x', parent=None, config=None)\n// after\nnode = MyItem.from_parent(parent=collector, name='x')","handlingStrategy":"type-guard","validationCode":"assert config is not None or parent is not None, 'config or parent required'","typeGuard":"def _node_has_config_source(config, parent) -> bool:\n    return config is not None or parent is not None","tryCatchPattern":null,"preventionTips":["Always construct nodes via from_parent so config is inherited.","Never instantiate Node subclasses directly in plugins."],"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"}