Skip to content

Commit 1dd2483

Browse files
remove the __in_named_ctor concpet, its not needed with the simplification
1 parent fe251f4 commit 1dd2483

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/_pytest/nodes.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,11 @@ class NodeMeta(type):
7070
__in_named_ctor = False
7171

7272
def __call__(self, *k, **kw):
73-
if not self.__in_named_ctor:
74-
warnings.warn(NODE_USE_FROM_PARENT.format(name=self.__name__), stacklevel=3)
75-
return self._create(*k, **kw)
76-
77-
@contextmanager
78-
def __ctor_entered(self):
79-
self.__in_named_ctor = True
80-
yield
81-
self.__in_named_ctor = False
73+
warnings.warn(NODE_USE_FROM_PARENT.format(name=self.__name__), stacklevel=3)
74+
return super().__call__(*k, **kw)
8275

8376
def _create(self, *k, **kw):
84-
with self.__ctor_entered():
85-
return super().__call__(*k, **kw)
77+
return super().__call__(*k, **kw)
8678

8779

8880
class Node(metaclass=NodeMeta):
@@ -128,8 +120,8 @@ def __init__(
128120
self._nodeid += "::" + self.name
129121

130122
@classmethod
131-
def from_parent(cls, parent, **kw):
132-
return cls._create(**kw, parent=parent)
123+
def from_parent(cls, parent, *, name):
124+
return cls._create(parent=parent, name=name)
133125

134126
@property
135127
def ihook(self):
@@ -411,6 +403,10 @@ def __init__(self, fspath, parent=None, config=None, session=None, nodeid=None):
411403

412404
super().__init__(name, parent, config, session, nodeid=nodeid, fspath=fspath)
413405

406+
@classmethod
407+
def from_parent(cls, parent, *, fspath):
408+
return cls._create(parent=parent, fspath=fspath)
409+
414410

415411
class File(FSCollector):
416412
""" base class for collecting tests from a file. """

src/_pytest/python.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,12 @@ def __init__(
14011401
#: .. versionadded:: 3.0
14021402
self.originalname = originalname
14031403

1404+
@classmethod
1405+
def from_parent(
1406+
cls, parent, **kw
1407+
):
1408+
return cls._create(parent=parent, **kw)
1409+
14041410
def _initrequest(self):
14051411
self.funcargs = {}
14061412
self._request = fixtures.FixtureRequest(self)

0 commit comments

Comments
 (0)