Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

item.obj is again a bound method on TestCase function items #5393

Merged
merged 1 commit into from Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/5390.bugfix.rst
@@ -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
Expand Up @@ -108,11 +108,13 @@ class TestCaseFunction(Function):

def setup(self):
self._testcase = self.parent.obj(self.name)
self._obj = getattr(self._testcase, self.name)
if hasattr(self, "_request"):
self._request._fillfixtures()

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
Expand Up @@ -139,6 +139,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