Opened 4 years ago

Closed 4 years ago

#13851 closed (invalid)

Clarification of the 'Fixture loading' section of the unit test documentation

Reported by: igloo Owned by: nobody
Component: Documentation Version: 1.2
Severity: Keywords: fixtures, testing framework, unit tests, initial_data
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


The documentation could do with elaborating on the loading of fixtures by the testing framework.

Quoth the docs:

"Once you've created a fixture and placed it in a fixtures directory in one of your INSTALLED_APPS, you can use it in your unit tests by specifying a fixtures class attribute on your django.test.TestCase subclass:"


class AnimalTestCase(TestCase):
    fixtures = ['mammals.json', 'birds']

What that says to me is, I can put any old file in the 'fixtures' directory and load it up in the test case by referring to it by filename, eg., 'mammals.json' - however, with the default behaviour, this isn't the case. The fixtures have to be in a file called 'initial_data'. I spent about 10 minutes tearing my hair out over this one! I know it does mention this in the box directly above the bit I've quoted, but is there any chance we can make it a bit clearer?

Attachments (0)

Change History (1)

comment:1 Changed 4 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

The provided example is completely correct. Test fixtures don't need to be called initial_data. If your fixture is named "initial_data" it will be loaded as a default fixture as part of the syncdb process.

If you're having difficulty loading fixtures that aren't called initial_data, then something else is going wrong. Please ask on django-users to debug the problem you are having.

Given that this appears to be a case of user error, I'm closing invalid. If it turns out that there is something that needs to be clarified, we can reopen once the problem has been established.

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.