Skip to content

Commit c9062ed

Browse files
committed
warn via NodeMeta
1 parent 89abdb9 commit c9062ed

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

‎src/_pytest/nodes.py‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,29 @@ def ischildnode(baseid, nodeid):
7575
return node_parts[: len(base_parts)] == base_parts
7676

7777

78-
class Node:
78+
class NodeMeta(type):
79+
def __call__(cls, *args, **kwargs):
80+
from _pytest.main import Session # noqa: F811
81+
82+
if cls is Session:
83+
# from_config
84+
assert len(args) == 1, args
85+
assert isinstance(args[0], Config), args
86+
assert not kwargs, kwargs
87+
else:
88+
# from_parent
89+
import inspect
90+
91+
sig = inspect.signature(cls.__init__)
92+
bsig = sig.bind(cls, *args, **kwargs)
93+
if "parent" not in bsig.arguments:
94+
warnings.warn(
95+
NODE_USE_FROM_PARENT.format(name=cls.__name__), stacklevel=2
96+
)
97+
return super().__call__(*args, **kwargs)
98+
99+
100+
class Node(metaclass=NodeMeta):
79101
""" base class for Collector and Item the test collection tree.
80102
Collector subclasses have children, Items are terminal nodes."""
81103

0 commit comments

Comments
 (0)