diff --git a/pytest_django/plugin.py b/pytest_django/plugin.py index 4c403da9e..3f499715b 100644 --- a/pytest_django/plugin.py +++ b/pytest_django/plugin.py @@ -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) diff --git a/tests/test_unittest.py b/tests/test_unittest.py index d4ecbc381..98699ab80 100644 --- a/tests/test_unittest.py +++ b/tests/test_unittest.py @@ -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