python: add back instance accessor to all python nodes, not just Function
Regressed in 062d91ab4 (pytest 7.0.0rc1 only).
Fix #9486.
This commit is contained in:
@@ -283,6 +283,16 @@ class PyobjMixin(nodes.Node):
|
||||
node = self.getparent(Class)
|
||||
return node.obj if node is not None else None
|
||||
|
||||
@property
|
||||
def instance(self):
|
||||
"""Python instance object the function is bound to.
|
||||
|
||||
Returns None if not a test method, e.g. for a standalone test function,
|
||||
a staticmethod, a class or a module.
|
||||
"""
|
||||
node = self.getparent(Function)
|
||||
return getattr(node.obj, "__self__", None) if node is not None else None
|
||||
|
||||
@property
|
||||
def obj(self):
|
||||
"""Underlying Python object."""
|
||||
@@ -1693,15 +1703,6 @@ class Function(PyobjMixin, nodes.Item):
|
||||
"""Underlying python 'function' object."""
|
||||
return getimfunc(self.obj)
|
||||
|
||||
@property
|
||||
def instance(self):
|
||||
"""Python instance object the function is bound to.
|
||||
|
||||
Returns None if not a test method, e.g. for a standalone test function
|
||||
or a staticmethod.
|
||||
"""
|
||||
return getattr(self.obj, "__self__", None)
|
||||
|
||||
def _getobj(self):
|
||||
assert self.parent is not None
|
||||
if isinstance(self.parent, Class):
|
||||
|
||||
Reference in New Issue
Block a user