|
1 | 1 | import os
|
2 | 2 | import warnings
|
3 |
| -from contextlib import contextmanager |
4 | 3 | from functools import lru_cache
|
5 | 4 | from typing import Any
|
6 | 5 | from typing import Dict
|
@@ -67,22 +66,12 @@ def ischildnode(baseid, nodeid):
|
67 | 66 |
|
68 | 67 |
|
69 | 68 | class NodeMeta(type):
|
70 |
| - __in_named_ctor = False |
71 |
| - |
72 | 69 | 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) |
82 | 72 |
|
83 | 73 | def _create(self, *k, **kw):
|
84 |
| - with self.__ctor_entered(): |
85 |
| - return super().__call__(*k, **kw) |
| 74 | + return super().__call__(*k, **kw) |
86 | 75 |
|
87 | 76 |
|
88 | 77 | class Node(metaclass=NodeMeta):
|
@@ -128,8 +117,8 @@ def __init__(
|
128 | 117 | self._nodeid += "::" + self.name
|
129 | 118 |
|
130 | 119 | @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) |
133 | 122 |
|
134 | 123 | @property
|
135 | 124 | def ihook(self):
|
@@ -411,6 +400,10 @@ def __init__(self, fspath, parent=None, config=None, session=None, nodeid=None):
|
411 | 400 |
|
412 | 401 | super().__init__(name, parent, config, session, nodeid=nodeid, fspath=fspath)
|
413 | 402 |
|
| 403 | + @classmethod |
| 404 | + def from_parent(cls, parent, *, fspath): |
| 405 | + return cls._create(parent=parent, fspath=fspath) |
| 406 | + |
414 | 407 |
|
415 | 408 | class File(FSCollector):
|
416 | 409 | """ base class for collecting tests from a file. """
|
|
0 commit comments