Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/_pytest/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ def safe_isclass(obj):
"Collector",
"Module",
"Function",
"Instance",
"Session",
"Item",
"Class",
Expand Down
13 changes: 1 addition & 12 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ def pytest_sessionstart(session):
scope2props["package"] = ("fspath",)
scope2props["module"] = ("fspath", "module")
scope2props["class"] = scope2props["module"] + ("cls",)
scope2props["instance"] = scope2props["class"] + ("instance",)
scope2props["function"] = scope2props["instance"] + ("function", "keywords")
scope2props["function"] = scope2props["class"] + ("function", "keywords")


def scopeproperty(name=None, doc=None):
Expand Down Expand Up @@ -399,16 +398,6 @@ def cls(self):
if clscol:
return clscol.obj

@property
def instance(self):
""" instance (can be None) on which test function was collected. """
# unittest support hack, see _pytest.unittest.TestCaseFunction
try:
return self._pyfuncitem._testcase
except AttributeError:
function = getattr(self, "function", None)
return getattr(function, "__self__", None)

@scopeproperty()
def module(self):
""" python module object where the test function was collected. """
Expand Down
6 changes: 1 addition & 5 deletions src/_pytest/mark/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,8 @@ def __init__(self, names):
def from_item(cls, item):
mapped_names = set()

# Add the names of the current item and any parent items
import pytest

for item in item.listchain():
if not isinstance(item, pytest.Instance):
mapped_names.add(item.name)
mapped_names.add(item.name)

# Add the names added as extra keywords to current or parent items
mapped_names.update(item.listextrakeywords())
Expand Down
4 changes: 1 addition & 3 deletions src/_pytest/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ def __init__(
assert "::()" not in nodeid
self._nodeid = nodeid
else:
self._nodeid = self.parent.nodeid
if self.name != "()":
self._nodeid += "::" + self.name
self._nodeid = self.parent.nodeid + "::" + self.name

@property
def ihook(self):
Expand Down
33 changes: 6 additions & 27 deletions src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ def async_warn():
async_warn()
funcargs = pyfuncitem.funcargs
testargs = {arg: funcargs[arg] for arg in pyfuncitem._fixtureinfo.argnames}
if isinstance(pyfuncitem.parent, Class):
inst = pyfuncitem.parent.obj()
testfunction = testfunction.__get__(inst, type(inst))
result = testfunction(**testargs)
if hasattr(result, "__await__") or hasattr(result, "__aiter__"):
async_warn()
Expand Down Expand Up @@ -242,7 +245,6 @@ def pytest_make_parametrize_id(config, val, argname=None):
class PyobjContext:
module = pyobj_property("Module")
cls = pyobj_property("Class")
instance = pyobj_property("Instance")


class PyobjMixin(PyobjContext):
Expand All @@ -256,8 +258,7 @@ def obj(self):
self._obj = obj = self._getobj()
# XXX evil hack
# used to avoid Instance collector marker duplication
if self._ALLOW_MARKERS:
self.own_markers.extend(get_unpacked_marks(self.obj))
self.own_markers.extend(get_unpacked_marks(self.obj))
return obj

@obj.setter
Expand All @@ -274,8 +275,6 @@ def getmodpath(self, stopatmodule=True, includemodule=False):
chain.reverse()
parts = []
for node in chain:
if isinstance(node, Instance):
continue
name = node.name
if isinstance(node, Module):
name = os.path.splitext(name)[0]
Expand Down Expand Up @@ -709,7 +708,7 @@ def collect(self):
self._inject_setup_class_fixture()
self._inject_setup_method_fixture()

return [Instance(name="()", parent=self)]
return super().collect()

def _inject_setup_class_fixture(self):
"""Injects a hidden autouse, class scoped fixture into the collected class object
Expand Down Expand Up @@ -761,33 +760,13 @@ def xunit_setup_method_fixture(self, request):
self.obj.__pytest_setup_method = xunit_setup_method_fixture


class Instance(PyCollector):
_ALLOW_MARKERS = False # hack, destroy later
# instances share the object with their parents in a way
# that duplicates markers instances if not taken out
# can be removed at node structure reorganization time

def _getobj(self):
return self.parent.obj()

def collect(self):
self.session._fixturemanager.parsefactories(self)
return super().collect()

def newinstance(self):
self.obj = self._getobj()
return self.obj


class FunctionMixin(PyobjMixin):
""" mixin for the code common to Function and Generator.
"""

def setup(self):
""" perform setup for this test function. """
if isinstance(self.parent, Instance):
self.parent.newinstance()
self.obj = self._getobj()
self.obj = self._getobj()

def _prunetraceback(self, excinfo):
if hasattr(self, "_obj") and not self.config.getoption("fulltrace", False):
Expand Down
2 changes: 0 additions & 2 deletions src/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from _pytest.outcomes import xfail
from _pytest.python import Class
from _pytest.python import Function
from _pytest.python import Instance
from _pytest.python import Module
from _pytest.python import Package
from _pytest.python_api import approx
Expand Down Expand Up @@ -66,7 +65,6 @@
"hookimpl",
"hookspec",
"importorskip",
"Instance",
"Item",
"main",
"mark",
Expand Down