Skip to content

Commit 57b1f33

Browse files
WIP: more detailed ctor handling
1 parent fd1d330 commit 57b1f33

File tree

1 file changed

+45
-7
lines changed

1 file changed

+45
-7
lines changed

src/_pytest/nodes.py

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,30 +115,57 @@ class Node(metaclass=NodeMeta):
115115
"__dict__",
116116
)
117117

118+
name: str
119+
parent: Optional["Node"]
120+
config: Config
121+
session: "Session"
122+
fs_path: Path
123+
_nodeid: str
124+
118125
def __init__(
119126
self,
120127
*,
121128
name: str,
122129
parent: Optional["Node"],
123-
config: Config,
124-
session: "Session",
125-
fs_path: Path,
126-
nodeid: str,
130+
config: Optional[Config],
131+
session: Optional["Session"],
132+
fs_path: Optional[Path],
133+
nodeid: Optional[str],
127134
) -> None:
128135
#: A unique name within the scope of the parent node.
129136
self.name = name
137+
138+
if nodeid is not None:
139+
assert "::()" not in nodeid
140+
else:
141+
assert parent is not None
142+
nodeid = parent.nodeid
143+
if name != "()":
144+
nodeid = f"{nodeid}::{name}"
130145
self._nodeid = nodeid
131146
#: The parent collector node.
132147
self.parent = parent
133148

134149
#: The pytest config object.
135-
self.config = config
150+
if config is None:
151+
assert parent is not None
152+
self.config = parent.config
153+
else:
154+
self.config = config
136155

137156
#: The pytest session this node is part of.
138-
self.session = session
157+
if session is None:
158+
assert parent is not None
159+
self.session = parent.session
160+
else:
161+
self.session = session
139162

140163
#: Filesystem path where this node was collected from (can be None).
141-
self.fs_path = fs_path
164+
if fs_path is None:
165+
assert parent is not None
166+
self.fs_path = parent.fs_path
167+
else:
168+
self.fs_path = fs_path
142169

143170
#: Keywords/markers collected from all scopes.
144171
self.keywords = NodeKeywords(self)
@@ -509,6 +536,17 @@ def _check_initialpaths_for_relpath(
509536

510537

511538
class FSCollector(Collector):
539+
def __init__(self, **kw):
540+
541+
fs_path: Optional[Path] = kw.pop("fs_path", None)
542+
fspath: Optional[py.path.local] = kw.pop("fspath", None)
543+
544+
if fspath is not None:
545+
assert fs_path is None
546+
fs_path = Path(fspath)
547+
kw["fs_path"] = fs_path
548+
super().__init__(**kw)
549+
512550
@classmethod
513551
def from_parent(
514552
cls,

0 commit comments

Comments
 (0)