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 @@ -108,11 +108,13 @@ class TestCaseFunction(Function):
108
108
109
109
def setup (self ):
110
110
self ._testcase = self .parent .obj (self .name )
111
+ self ._obj = getattr (self ._testcase , self .name )
111
112
if hasattr (self , "_request" ):
112
113
self ._request ._fillfixtures ()
113
114
114
115
def teardown (self ):
115
116
self ._testcase = None
117
+ self ._obj = None
116
118
117
119
def startTest (self , testcase ):
118
120
pass
Original file line number Diff line number Diff line change @@ -139,6 +139,29 @@ def test_func2(self):
139
139
reprec .assertoutcome (passed = 2 )
140
140
141
141
142
+ def test_function_item_obj_is_instance (testdir ):
143
+ """item.obj should be a bound method on unittest.TestCase function items (#5390)."""
144
+ testdir .makeconftest (
145
+ """
146
+ def pytest_runtest_makereport(item, call):
147
+ if call.when == 'call':
148
+ class_ = item.parent.obj
149
+ assert isinstance(item.obj.__self__, class_)
150
+ """
151
+ )
152
+ testdir .makepyfile (
153
+ """
154
+ import unittest
155
+
156
+ class Test(unittest.TestCase):
157
+ def test_foo(self):
158
+ pass
159
+ """
160
+ )
161
+ result = testdir .runpytest_inprocess ()
162
+ result .stdout .fnmatch_lines (["* 1 passed in*" ])
163
+
164
+
142
165
def test_teardown (testdir ):
143
166
testpath = testdir .makepyfile (
144
167
"""
You can’t perform that action at this time.
0 commit comments