remove the legacy code about im_func and generalize using fix and compat.getimfunc

This commit is contained in:
Ronny Pfannschmidt 2018-09-13 15:38:36 +02:00
parent 2cf2dc3d95
commit a0ce9a4441
3 changed files with 8 additions and 12 deletions

View File

@ -37,6 +37,7 @@ from _pytest.compat import (
getlocation,
enum,
get_default_arg_names,
getimfunc,
)
from _pytest.outcomes import fail
from _pytest.mark.structures import (
@ -681,14 +682,12 @@ class Class(PyCollector):
def setup(self):
setup_class = _get_xunit_func(self.obj, "setup_class")
if setup_class is not None:
setup_class = getattr(setup_class, "im_func", setup_class)
setup_class = getattr(setup_class, "__func__", setup_class)
setup_class = getimfunc(setup_class)
setup_class(self.obj)
fin_class = getattr(self.obj, "teardown_class", None)
if fin_class is not None:
fin_class = getattr(fin_class, "im_func", fin_class)
fin_class = getattr(fin_class, "__func__", fin_class)
fin_class = getimfunc(fin_class)
self.addfinalizer(lambda: fin_class(self.obj))
@ -1433,7 +1432,7 @@ class Function(FunctionMixin, nodes.Item, fixtures.FuncargnamesCompatAttr):
@property
def function(self):
"underlying python 'function' object"
return getattr(self.obj, "im_func", self.obj)
return getimfunc(self.obj)
def _getobj(self):
name = self.name

View File

@ -9,6 +9,7 @@ import _pytest._code
from _pytest.config import hookimpl
from _pytest.outcomes import fail, skip, xfail
from _pytest.python import transfer_markers, Class, Module, Function
from _pytest.compat import getimfunc
def pytest_pycollect_makeitem(collector, name, obj):
@ -53,7 +54,7 @@ class UnitTestCase(Class):
x = getattr(self.obj, name)
if not getattr(x, "__test__", True):
continue
funcobj = getattr(x, "im_func", x)
funcobj = getimfunc(x)
transfer_markers(funcobj, cls, module)
yield TestCaseFunction(name, parent=self, callobj=funcobj)
foundsomething = True

View File

@ -796,7 +796,7 @@ class TestMetafuncFunctional(object):
p = testdir.makepyfile(
"""
# assumes that generate/provide runs in the same process
import sys, pytest
import sys, pytest, six
def pytest_generate_tests(metafunc):
metafunc.addcall(param=metafunc)
@ -815,11 +815,7 @@ class TestMetafuncFunctional(object):
def test_method(self, metafunc, pytestconfig):
assert metafunc.config == pytestconfig
assert metafunc.module.__name__ == __name__
if sys.version_info > (3, 0):
unbound = TestClass.test_method
else:
unbound = TestClass.test_method.im_func
# XXX actually have an unbound test function here?
unbound = six.get_unbound_function(TestClass.test_method)
assert metafunc.function == unbound
assert metafunc.cls == TestClass
"""