Skip to content
Merged
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: 1 addition & 0 deletions changelog/3975.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove legacy code around im_func as that was python2 only
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python 2.6 you mean?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicoddemus python2.7 supports the modern properties but was also based on the old ones, i believe the message is accurate enough ^^

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh OK, now I get it. Thanks!

9 changes: 4 additions & 5 deletions src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
getlocation,
enum,
get_default_arg_names,
getimfunc,
)
from _pytest.outcomes import fail
from _pytest.mark.structures import (
Expand Down Expand Up @@ -681,14 +682,12 @@ def collect(self):
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))


Expand Down Expand Up @@ -1433,7 +1432,7 @@ def _initrequest(self):
@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
Expand Down
3 changes: 2 additions & 1 deletion src/_pytest/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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):
Expand Down Expand Up @@ -53,7 +54,7 @@ def collect(self):
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
Expand Down
8 changes: 2 additions & 6 deletions testing/python/metafunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ def test_attributes(self, testdir):
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)

Expand All @@ -815,11 +815,7 @@ class TestClass(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
"""
Expand Down