Skip to content

Commit 49800ea

Browse files
authored
Merge pull request #3977 from RonnyPfannschmidt/remove-im-func
Remove im_func
2 parents 2cf2dc3 + 8fe55b1 commit 49800ea

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

changelog/3975.trivial.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove legacy code around im_func as that was python2 only

src/_pytest/python.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
getlocation,
3838
enum,
3939
get_default_arg_names,
40+
getimfunc,
4041
)
4142
from _pytest.outcomes import fail
4243
from _pytest.mark.structures import (
@@ -681,14 +682,12 @@ def collect(self):
681682
def setup(self):
682683
setup_class = _get_xunit_func(self.obj, "setup_class")
683684
if setup_class is not None:
684-
setup_class = getattr(setup_class, "im_func", setup_class)
685-
setup_class = getattr(setup_class, "__func__", setup_class)
685+
setup_class = getimfunc(setup_class)
686686
setup_class(self.obj)
687687

688688
fin_class = getattr(self.obj, "teardown_class", None)
689689
if fin_class is not None:
690-
fin_class = getattr(fin_class, "im_func", fin_class)
691-
fin_class = getattr(fin_class, "__func__", fin_class)
690+
fin_class = getimfunc(fin_class)
692691
self.addfinalizer(lambda: fin_class(self.obj))
693692

694693

@@ -1433,7 +1432,7 @@ def _initrequest(self):
14331432
@property
14341433
def function(self):
14351434
"underlying python 'function' object"
1436-
return getattr(self.obj, "im_func", self.obj)
1435+
return getimfunc(self.obj)
14371436

14381437
def _getobj(self):
14391438
name = self.name

src/_pytest/unittest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from _pytest.config import hookimpl
1010
from _pytest.outcomes import fail, skip, xfail
1111
from _pytest.python import transfer_markers, Class, Module, Function
12+
from _pytest.compat import getimfunc
1213

1314

1415
def pytest_pycollect_makeitem(collector, name, obj):
@@ -53,7 +54,7 @@ def collect(self):
5354
x = getattr(self.obj, name)
5455
if not getattr(x, "__test__", True):
5556
continue
56-
funcobj = getattr(x, "im_func", x)
57+
funcobj = getimfunc(x)
5758
transfer_markers(funcobj, cls, module)
5859
yield TestCaseFunction(name, parent=self, callobj=funcobj)
5960
foundsomething = True

testing/python/metafunc.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ def test_attributes(self, testdir):
796796
p = testdir.makepyfile(
797797
"""
798798
# assumes that generate/provide runs in the same process
799-
import sys, pytest
799+
import sys, pytest, six
800800
def pytest_generate_tests(metafunc):
801801
metafunc.addcall(param=metafunc)
802802
@@ -815,11 +815,7 @@ class TestClass(object):
815815
def test_method(self, metafunc, pytestconfig):
816816
assert metafunc.config == pytestconfig
817817
assert metafunc.module.__name__ == __name__
818-
if sys.version_info > (3, 0):
819-
unbound = TestClass.test_method
820-
else:
821-
unbound = TestClass.test_method.im_func
822-
# XXX actually have an unbound test function here?
818+
unbound = six.get_unbound_function(TestClass.test_method)
823819
assert metafunc.function == unbound
824820
assert metafunc.cls == TestClass
825821
"""

0 commit comments

Comments
 (0)