Skip to content

Commit 5217483

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

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

src/_pytest/nodes.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import warnings
3-
from contextlib import contextmanager
43
from functools import lru_cache
54
from typing import Any
65
from typing import Dict
@@ -67,22 +66,12 @@ def ischildnode(baseid, nodeid):
6766

6867

6968
class NodeMeta(type):
70-
__in_named_ctor = False
71-
7269
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
70+
warnings.warn(NODE_USE_FROM_PARENT.format(name=self.__name__), stacklevel=3)
71+
return super().__call__(*k, **kw)
8272

8373
def _create(self, *k, **kw):
84-
with self.__ctor_entered():
85-
return super().__call__(*k, **kw)
74+
return super().__call__(*k, **kw)
8675

8776

8877
class Node(metaclass=NodeMeta):
@@ -128,8 +117,8 @@ def __init__(
128117
self._nodeid += "::" + self.name
129118

130119
@classmethod
131-
def from_parent(cls, parent, **kw):
132-
return cls._create(**kw, parent=parent)
120+
def from_parent(cls, parent, *, name):
121+
return cls._create(parent=parent, name=name)
133122

134123
@property
135124
def ihook(self):
@@ -411,6 +400,10 @@ def __init__(self, fspath, parent=None, config=None, session=None, nodeid=None):
411400

412401
super().__init__(name, parent, config, session, nodeid=nodeid, fspath=fspath)
413402

403+
@classmethod
404+
def from_parent(cls, parent, *, fspath):
405+
return cls._create(parent=parent, fspath=fspath)
406+
414407

415408
class File(FSCollector):
416409
""" base class for collecting tests from a file. """

src/_pytest/python.py

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

1404+
@classmethod
1405+
def from_parent(cls, parent, **kw):
1406+
return cls._create(parent=parent, **kw)
1407+
14041408
def _initrequest(self):
14051409
self.funcargs = {}
14061410
self._request = fixtures.FixtureRequest(self)

0 commit comments

Comments
 (0)