-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Node from parent #5975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Node from parent #5975
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| Deprecate using direct constructors for ``Nodes``. | ||
|
|
||
| Instead they are new constructed via ``Node.from_parent``. | ||
|
|
||
| This transitional mechanism enables us to detangle the very intensely | ||
| entangled ``Node`` relationships by enforcing more controlled creation/configruation patterns. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| from _pytest.compat import cached_property | ||
| from _pytest.compat import getfslineno | ||
| from _pytest.config import Config | ||
| from _pytest.deprecated import NODE_USE_FROM_PARENT | ||
| from _pytest.fixtures import FixtureDef | ||
| from _pytest.fixtures import FixtureLookupError | ||
| from _pytest.fixtures import FixtureLookupErrorRepr | ||
|
|
@@ -73,7 +74,16 @@ def ischildnode(baseid, nodeid): | |
| return node_parts[: len(base_parts)] == base_parts | ||
|
|
||
|
|
||
| class Node: | ||
| class NodeMeta(type): | ||
bluetech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def __call__(self, *k, **kw): | ||
RonnyPfannschmidt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| warnings.warn(NODE_USE_FROM_PARENT.format(name=self.__name__), stacklevel=2) | ||
| return super().__call__(*k, **kw) | ||
|
|
||
| def _create(self, *k, **kw): | ||
| return super().__call__(*k, **kw) | ||
|
|
||
|
|
||
| class Node(metaclass=NodeMeta): | ||
| """ base class for Collector and Item the test collection tree. | ||
| Collector subclasses have children, Items are terminal nodes.""" | ||
|
|
||
|
|
@@ -133,6 +143,10 @@ def __init__( | |
| if self.name != "()": | ||
| self._nodeid += "::" + self.name | ||
|
|
||
| @classmethod | ||
| def from_parent(cls, parent, *, name): | ||
| return cls._create(parent=parent, name=name) | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the benefit compared to making There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i need to establish a distinct construction pattern in order to then follow up with cleaning up the node construction (thats overly smart and auto-creating different things) i tried a few times before without that and just failed flat on those occasions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. I think raising TypeErrors and using type annotations in general could be enough? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as soon as the ctor situation is largely resolved and the pattern is established, the meta class can go |
||
| @property | ||
| def ihook(self): | ||
| """ fspath sensitive hook proxy used to call pytest hooks""" | ||
|
|
@@ -418,6 +432,10 @@ def __init__( | |
|
|
||
| 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. """ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.