diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py index ead9ffd8d80..eebba72355b 100644 --- a/src/_pytest/compat.py +++ b/src/_pytest/compat.py @@ -377,7 +377,6 @@ def safe_str(v): "Module", "Generator", "Function", - "Instance", "Session", "Item", "Class", diff --git a/src/_pytest/mark/legacy.py b/src/_pytest/mark/legacy.py index cea136bff74..1fc30a87179 100644 --- a/src/_pytest/mark/legacy.py +++ b/src/_pytest/mark/legacy.py @@ -38,11 +38,8 @@ 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 for name in item.listextrakeywords(): diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index 0d65dc96537..cdda84b46c4 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -119,7 +119,6 @@ def ihook(self): Module = _CompatProperty("Module") Class = _CompatProperty("Class") - Instance = _CompatProperty("Instance") Function = _CompatProperty("Function") File = _CompatProperty("File") Item = _CompatProperty("Item") diff --git a/src/_pytest/nose.py b/src/_pytest/nose.py index 4bfa9c5838b..cc38e67c6b3 100644 --- a/src/_pytest/nose.py +++ b/src/_pytest/nose.py @@ -34,8 +34,9 @@ def pytest_runtest_setup(item): gen = item.parent if not hasattr(gen, "_nosegensetup"): call_optional(gen.obj, "setup") - if isinstance(gen.parent, python.Instance): - call_optional(gen.parent.obj, "setup") + # XXX + # if isinstance(gen.parent, python.Instance): + # call_optional(gen.parent.obj, "setup") gen._nosegensetup = True if not call_optional(item.obj, "setup"): # call module level setup if there is no object level one diff --git a/src/_pytest/python.py b/src/_pytest/python.py index d360e2c8f3e..b1d1551ff59 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -232,7 +232,6 @@ def pytest_make_parametrize_id(config, val, argname=None): class PyobjContext(object): module = pyobj_property("Module") cls = pyobj_property("Class") - instance = pyobj_property("Instance") class PyobjMixin(PyobjContext): @@ -268,8 +267,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] @@ -629,10 +626,13 @@ def _get_xunit_func(obj, name): class Class(PyCollector): """ Collector for test methods. """ + def _getobj(self): + return getattr(self.parent.obj, self.name)() + def collect(self): if not safe_getattr(self.obj, "__test__", True): return [] - if hasinit(self.obj): + if hasinit(self.obj.__class__): self.warn( PytestWarning( "cannot collect test class %r because it has a " @@ -640,7 +640,7 @@ def collect(self): ) ) return [] - elif hasnew(self.obj): + elif hasnew(self.obj.__class__): self.warn( PytestWarning( "cannot collect test class %r because it has a " @@ -648,7 +648,8 @@ def collect(self): ) ) return [] - return [self._getcustomclass("Instance")(name="()", parent=self)] + self.session._fixturemanager.parsefactories(self) + return super(Class, self).collect() def setup(self): setup_class = _get_xunit_func(self.obj, "setup_class") @@ -662,24 +663,6 @@ def setup(self): self.addfinalizer(lambda: fin_class(self.obj)) -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(Instance, self).collect() - - def newinstance(self): - self.obj = self._getobj() - return self.obj - - class FunctionMixin(PyobjMixin): """ mixin for the code common to Function and Generator. """ @@ -688,9 +671,6 @@ def setup(self): """ perform setup for this test function. """ if hasattr(self, "_preservedparent"): obj = self._preservedparent - elif isinstance(self.parent, Instance): - obj = self.parent.newinstance() - self.obj = self._getobj() else: obj = self.parent.obj if inspect.ismethod(self.obj): diff --git a/src/pytest.py b/src/pytest.py index 14ed1acaab8..00ae42242ec 100644 --- a/src/pytest.py +++ b/src/pytest.py @@ -29,7 +29,6 @@ from _pytest.python import Class from _pytest.python import Function from _pytest.python import Generator -from _pytest.python import Instance from _pytest.python import Module from _pytest.python import Package from _pytest.python_api import approx @@ -61,7 +60,6 @@ "hookimpl", "hookspec", "importorskip", - "Instance", "Item", "main", "mark", diff --git a/testing/python/collect.py b/testing/python/collect.py index 61039a50678..645b2b1eab0 100644 --- a/testing/python/collect.py +++ b/testing/python/collect.py @@ -1370,7 +1370,6 @@ def test_collector_attributes(testdir): def pytest_pycollect_makeitem(collector): assert collector.Function == pytest.Function assert collector.Class == pytest.Class - assert collector.Instance == pytest.Instance assert collector.Module == pytest.Module """ ) @@ -1390,10 +1389,8 @@ def test_customize_through_attributes(testdir): import pytest class MyFunction(pytest.Function): pass - class MyInstance(pytest.Instance): - Function = MyFunction class MyClass(pytest.Class): - Instance = MyInstance + Function = MyFunction def pytest_pycollect_makeitem(collector, name, obj): if name.startswith("MyTestClass"): @@ -1408,9 +1405,7 @@ def test_hello(self): """ ) result = testdir.runpytest("--collect-only") - result.stdout.fnmatch_lines( - ["*MyClass*", "*MyInstance*", "*MyFunction*test_hello*"] - ) + result.stdout.fnmatch_lines(["*MyClass*", "*MyFunction*test_hello*"]) def test_unorderable_types(testdir):