Skip to content

Commit

Permalink
Merge pull request #5393 from nicoddemus/unittest-self-5390
Browse files Browse the repository at this point in the history
item.obj is again a bound method on TestCase function items
  • Loading branch information
asottile committed Jun 5, 2019
1 parent 937f945 commit 92432ac
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/5390.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix regression where the ``obj`` attribute of ``TestCase`` items was no longer bound to methods.
2 changes: 2 additions & 0 deletions src/_pytest/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class TestCaseFunction(Function):
def setup(self):
self._testcase = self.parent.obj(self.name)
self._fix_unittest_skip_decorator()
self._obj = getattr(self._testcase, self.name)
if hasattr(self, "_request"):
self._request._fillfixtures()

Expand All @@ -132,6 +133,7 @@ def _fix_unittest_skip_decorator(self):

def teardown(self):
self._testcase = None
self._obj = None

def startTest(self, testcase):
pass
Expand Down
23 changes: 23 additions & 0 deletions testing/test_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,29 @@ def test_func2(self):
reprec.assertoutcome(passed=2)


def test_function_item_obj_is_instance(testdir):
"""item.obj should be a bound method on unittest.TestCase function items (#5390)."""
testdir.makeconftest(
"""
def pytest_runtest_makereport(item, call):
if call.when == 'call':
class_ = item.parent.obj
assert isinstance(item.obj.__self__, class_)
"""
)
testdir.makepyfile(
"""
import unittest
class Test(unittest.TestCase):
def test_foo(self):
pass
"""
)
result = testdir.runpytest_inprocess()
result.stdout.fnmatch_lines(["* 1 passed in*"])


def test_teardown(testdir):
testpath = testdir.makepyfile(
"""
Expand Down

0 comments on commit 92432ac

Please sign in to comment.