Opened 14 years ago

Closed 14 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: no UI/UX: no

Description

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?

Change History (1)

comment:1 by Russell Keith-Magee, 14 years ago

Resolution: invalid
Status: newclosed

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.

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