diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py index 3898fb252a1..4a6f8658001 100644 --- a/src/_pytest/compat.py +++ b/src/_pytest/compat.py @@ -308,7 +308,6 @@ def safe_isclass(obj): "Collector", "Module", "Function", - "Instance", "Session", "Item", "Class", diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index b4b10fcd249..3e16acd26d9 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -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): @@ -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. """ diff --git a/src/_pytest/mark/legacy.py b/src/_pytest/mark/legacy.py index d14ea3a8274..017b46125aa 100644 --- a/src/_pytest/mark/legacy.py +++ b/src/_pytest/mark/legacy.py @@ -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()) diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index e6dee15470c..e2d65f3101f 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -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): diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 913a93bc025..fc88a8f6687 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -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() @@ -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): @@ -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 @@ -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] @@ -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 @@ -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): diff --git a/src/pytest.py b/src/pytest.py index b934e65cb8c..e863b9dc575 100644 --- a/src/pytest.py +++ b/src/pytest.py @@ -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 @@ -66,7 +65,6 @@ "hookimpl", "hookspec", "importorskip", - "Instance", "Item", "main", "mark",