File tree Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Expand file tree Collapse file tree 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):
108108
109109 def setup (self ):
110110 self ._testcase = self .parent .obj (self .name )
111+ self ._obj = getattr (self ._testcase , self .name )
111112 if hasattr (self , "_request" ):
112113 self ._request ._fillfixtures ()
113114
114115 def teardown (self ):
115116 self ._testcase = None
117+ self ._obj = None
116118
117119 def startTest (self , testcase ):
118120 pass
Original file line number Diff line number Diff line change @@ -139,6 +139,29 @@ def test_func2(self):
139139 reprec .assertoutcome (passed = 2 )
140140
141141
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+
142165def test_teardown (testdir ):
143166 testpath = testdir .makepyfile (
144167 """
You can’t perform that action at this time.
0 commit comments