Skip to content

Commit 1bf4920

Browse files
committed
Fix regression introduced in 96f5fb1.
The previous fix did not properly check the full MRO chain when looking for the super method, which then failed when used with mixins that does not define setUpClass/tearDownClass. This commit fixes issue pytest-dev#280.
1 parent 7825837 commit 1bf4920

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pytest_django/plugin.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,15 @@ def pytest_configure():
251251

252252

253253
def _method_is_defined_at_leaf(cls, method_name):
254-
return getattr(cls.__base__, method_name).__func__ is not getattr(cls, method_name).__func__
254+
super_method = None
255+
256+
for base_cls in cls.__bases__:
257+
if hasattr(base_cls, method_name):
258+
super_method = getattr(base_cls, method_name)
259+
260+
assert super_method is not None, '%s could not be found in base class' % method_name
261+
262+
return getattr(cls, method_name).__func__ is not super_method.__func__
255263

256264

257265
_disabled_classmethods = {}

tests/test_unittest.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,13 @@ def test_multi_inheritance_setUpClass(self, django_testdir):
124124
from django.test import TestCase
125125
from .app.models import Item
126126
127-
class TestA(TestCase):
127+
# Using a mixin is a regression test, see #280 for more details:
128+
# https://github.com/pytest-dev/pytest-django/issues/280
129+
130+
class SomeMixin(object):
131+
pass
132+
133+
class TestA(SomeMixin, TestCase):
128134
expected_state = ['A']
129135
state = []
130136

0 commit comments

Comments
 (0)