File tree 3 files changed +26
-0
lines changed 3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ Fix regression where the ``obj `` attribute of ``TestCase `` items was no longer bound to methods.
Original file line number Diff line number Diff line change @@ -114,6 +114,7 @@ class TestCaseFunction(Function):
114
114
def setup (self ):
115
115
self ._testcase = self .parent .obj (self .name )
116
116
self ._fix_unittest_skip_decorator ()
117
+ self ._obj = getattr (self ._testcase , self .name )
117
118
if hasattr (self , "_request" ):
118
119
self ._request ._fillfixtures ()
119
120
@@ -132,6 +133,7 @@ def _fix_unittest_skip_decorator(self):
132
133
133
134
def teardown (self ):
134
135
self ._testcase = None
136
+ self ._obj = None
135
137
136
138
def startTest (self , testcase ):
137
139
pass
Original file line number Diff line number Diff line change @@ -144,6 +144,29 @@ def test_func2(self):
144
144
reprec .assertoutcome (passed = 2 )
145
145
146
146
147
+ def test_function_item_obj_is_instance (testdir ):
148
+ """item.obj should be a bound method on unittest.TestCase function items (#5390)."""
149
+ testdir .makeconftest (
150
+ """
151
+ def pytest_runtest_makereport(item, call):
152
+ if call.when == 'call':
153
+ class_ = item.parent.obj
154
+ assert isinstance(item.obj.__self__, class_)
155
+ """
156
+ )
157
+ testdir .makepyfile (
158
+ """
159
+ import unittest
160
+
161
+ class Test(unittest.TestCase):
162
+ def test_foo(self):
163
+ pass
164
+ """
165
+ )
166
+ result = testdir .runpytest_inprocess ()
167
+ result .stdout .fnmatch_lines (["* 1 passed in*" ])
168
+
169
+
147
170
def test_teardown (testdir ):
148
171
testpath = testdir .makepyfile (
149
172
"""
You can’t perform that action at this time.
0 commit comments