Skip to content

Commit

Permalink
remove the __in_named_ctor concpet, its not needed with the simplific…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
RonnyPfannschmidt committed Oct 29, 2019
1 parent fe251f4 commit 5217483
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/_pytest/nodes.py
@@ -1,6 +1,5 @@
import os
import warnings
from contextlib import contextmanager
from functools import lru_cache
from typing import Any
from typing import Dict
Expand Down Expand Up @@ -67,22 +66,12 @@ def ischildnode(baseid, nodeid):


class NodeMeta(type):
__in_named_ctor = False

def __call__(self, *k, **kw):
if not self.__in_named_ctor:
warnings.warn(NODE_USE_FROM_PARENT.format(name=self.__name__), stacklevel=3)
return self._create(*k, **kw)

@contextmanager
def __ctor_entered(self):
self.__in_named_ctor = True
yield
self.__in_named_ctor = False
warnings.warn(NODE_USE_FROM_PARENT.format(name=self.__name__), stacklevel=3)
return super().__call__(*k, **kw)

def _create(self, *k, **kw):
with self.__ctor_entered():
return super().__call__(*k, **kw)
return super().__call__(*k, **kw)


class Node(metaclass=NodeMeta):
Expand Down Expand Up @@ -128,8 +117,8 @@ def __init__(
self._nodeid += "::" + self.name

@classmethod
def from_parent(cls, parent, **kw):
return cls._create(**kw, parent=parent)
def from_parent(cls, parent, *, name):
return cls._create(parent=parent, name=name)

@property
def ihook(self):
Expand Down Expand Up @@ -411,6 +400,10 @@ def __init__(self, fspath, parent=None, config=None, session=None, nodeid=None):

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

@classmethod
def from_parent(cls, parent, *, fspath):
return cls._create(parent=parent, fspath=fspath)


class File(FSCollector):
""" base class for collecting tests from a file. """
Expand Down
4 changes: 4 additions & 0 deletions src/_pytest/python.py
Expand Up @@ -1401,6 +1401,10 @@ def __init__(
#: .. versionadded:: 3.0
self.originalname = originalname

@classmethod
def from_parent(cls, parent, **kw):
return cls._create(parent=parent, **kw)

def _initrequest(self):
self.funcargs = {}
self._request = fixtures.FixtureRequest(self)
Expand Down

0 comments on commit 5217483

Please sign in to comment.