Opened 10 years ago

Closed 10 years ago

#22989 closed Uncategorized (wontfix)

TestCase fixtures not found if inherited from other than first base class

Reported by: vilcans Owned by: nobody
Component: Testing framework Version: 1.7-rc-1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


This is a regression from 1.6.5, where I inherited the fixtures attribute from a mixin class. In 1.7c1, Django acts like the attribute isn't there.

How to reproduce

from django.test import TestCase

class Mixin(object):
    fixtures = ('my_fixture',)

class Base(TestCase):

class FixtureTest(Base, Mixin):
    def test_dummy(self):

In 1.7c1, running this test gives no warning that the my_fixture doesn't exist, which shows that Django doesn't try to load it.


Swapping the order of the base classes like this gives the expected result:

class FixtureTest(Mixin, Base):

Now running the test, Django tries to load the fixture, as it should:

/usr/local/lib/python2.7/dist-packages/django/core/management/commands/ UserWarning: No fixture named 'my_fixture' found.
  warnings.warn("No fixture named '%s' found." % fixture_name)

Change History (3)

comment:1 by vilcans, 10 years ago

Come to think of it, this may be good by design. Change the Mixin class to inherit from TestCase too and it works the way I expected it to. We get a diamond hierarchy but Python handles that well AFAIK. Then again, the inheritance order shouldn't make a difference.

Last edited 10 years ago by vilcans (previous) (diff)

comment:2 by Claude Paroz, 10 years ago

This behavior change is caused by [abb10db06fb2ecb3e897462ec72417d10b39b8a4] (fixing #21089).

However when using mixins, the base class should always be the rightmost class. Read for example. Therefore I'd tend to won't fix this ticket.

comment:3 by Tim Graham, 10 years ago

Resolution: wontfix
Status: newclosed

I agree with Claude.

Note: See TracTickets for help on using tickets.
Back to Top