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

Fix classmethod check for mixin case #618

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pytest_django/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,10 @@ def pytest_configure():
def _classmethod_is_defined_at_leaf(cls, method_name):
super_method = None

for base_cls in cls.__bases__:
for base_cls in cls.__mro__[1:]: # pragma: no branch
if hasattr(base_cls, method_name):
super_method = getattr(base_cls, method_name)
break

assert super_method is not None, (
'%s could not be found in base class' % method_name)
Expand Down
28 changes: 28 additions & 0 deletions tests/test_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,34 @@ def test_bar21(self):
])
assert result.ret == 0

def test_setUpClass_mixin(self, django_testdir):
django_testdir.create_test_module('''
from django.test import TestCase

class TheMixin(object):
@classmethod
def setUpClass(cls):
super(TheMixin, cls).setUpClass()


class TestFoo(TheMixin, TestCase):
def test_foo(self):
pass


class TestBar(TheMixin, TestCase):
def test_bar(self):
pass
''')

result = django_testdir.runpytest_subprocess('-v', '-s', '--pdb')
result.stdout.fnmatch_lines([
"*TestFoo::test_foo Creating test database for*",
"PASSED",
"*TestBar::test_bar PASSED*",
])
assert result.ret == 0

def test_setUpClass_skip(self, django_testdir):
django_testdir.create_test_module('''
from django.test import TestCase
Expand Down