{"record":{"id":"d2ccbefe110661f1","repo":"pytest-dev/pytest","slug":"session-or-parent-must-be-provided","errorCode":null,"errorMessage":"session or parent must be provided","messagePattern":"session or parent must be provided","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/_pytest/nodes.py","lineNumber":176,"sourceCode":"        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.\n        self.keywords: MutableMapping[str, Any] = NodeKeywords(self)\n\n        #: The marker objects belonging to this node.\n        self.own_markers: list[Mark] = []\n\n        #: Allow adding of extra keywords to use for matching.\n        self.extra_keyword_matches: set[str] = set()\n","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/nodes.py#L158-L194","documentation":"Raised by Node.__init__ when neither session nor parent is supplied. Mirroring the config check, lines 172-177 fall back to parent.session when session is None; absent both, the node has no session to anchor its hook proxy and nodeid, so construction is rejected. The session is load-bearing for ihook dispatch and test lifecycle.","triggerScenarios":"Node(...) with session=None and parent=None; constructing a node detached from the Session, e.g. in a unit test or a buggy plugin that bypasses from_parent.","commonSituations":"Plugin authors building nodes manually without a parent; mocking frameworks that construct nodes without a session fixture.","solutions":["Use Node.from_parent(parent, **kw) so session is inherited from parent.","Pass an explicit session object when constructing standalone.","Ensure a parent node is always provided in the construction chain."],"exampleFix":"// before\nnode = MyItem(name='x')\n// after\nnode = MyItem.from_parent(parent=collector, name='x')","handlingStrategy":"type-guard","validationCode":"assert session is not None or parent is not None, 'session or parent required'","typeGuard":"def _node_has_session_source(session, parent) -> bool:\n    return session is not None or parent is not None","tryCatchPattern":null,"preventionTips":["Construct nodes via from_parent to inherit session.","Pass the session fixture through when building standalone nodes."],"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"}