Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#241 closed defect (wontfix)

Test fixture support

Reported by: Caleb Davis Owned by:
Priority: minor Milestone:
Component: programming Keywords: post-sql
Cc: Parent Tickets:

Description (last modified by Christopher Allan Webber)

A few tickets are blocking on being able to rip test data into the
database, and some giant put me on his shoulders and then I saw the
promised land of test fixtures. We need to support test fixtures.

Change History (11)

comment:1 by Christopher Allan Webber, 13 years ago

There are two possible ways we could do this, too.

-  We could make use of the envball stuff we have. That would be
   easiest, maybe?
-  We could write something different. The envball stuff exports to
   I think binary database files which aren't so great for fixtures.
   What I'd really like are bson->json exports of the data and not
   gzipped tarballs... that would make it easier for us to edit our
   fixture data going forward as things change in a git-friendly way.

`#1 </issues/1>`_ is probably faster, #2 is probably nicer.

comment:2 by Caleb Davis, 13 years ago

2 would be fine I think. A thin wrapper around mongo{import/export} would seem to do the trick!

` <>`_

comment:3 by Christopher Allan Webber, 12 years ago


comment:3 by Elrond, 12 years ago

A simple start: Creating the test user in the database. I factored
that out into a tool function.
My branch: ``misc/fixture_add_user``.
If nobody cries "stupid idea" or "found a bug", I'll merge/push on

Okay, merged. (commit ea5a5b15a3d5)

comment:4 by Christopher Allan Webber, 12 years ago


comment:4 by Christopher Allan Webber, 12 years ago

The requirements for this have massively changed now that we're
moving to SQL, but I say "leave it open for now".

comment:5 by Will Kahn-Greene, 12 years ago

The original url for this bug was .
#142: related, #55: related, #379: blocked

comment:6 by Elrond, 12 years ago

Keywords: post-sql added

comment:7 by Elrond, 12 years ago

Milestone: 0.2.1

This will be interesting after sql lands.
sql hopefully lands in the next release.
So this will be after the next release, probably.

Of course, if someone wants to take it, go for it!

comment:8 by Christopher Allan Webber, 12 years ago

Description: modified (diff)
Resolution: wontfix
Status: acceptedclosed

I'm going to kill this one.

I saw a talk at pycon that significantly convinced me that test fixtures are the wrong way to go. See:

starting at 16:26

All sorts of reasons given for why this is bad!

Instead he suggests writing code like this:

def create_profile(**kwargs):
    defaults = {
        "likes_cheese": True,
        "age": 32,
        "address": "3815 Brookside Dr",
    if "user" not in defaults:
        defaults["user"] = create_user()
    return Profile.objects.create(

and using that to *only* change the fields that you need to test for each thing you're trying out.

fixture_add_user() as elrond made above already pretty close to this.

Anyway, wontfix'ing my own bug! :)

comment:9 by Will Kahn-Greene, 12 years ago

I didn't even know this bug was around.

Erik Rose's talk at PyCon 2012 also talk about problems with testing using fixtures:

Note: See TracTickets for help on using tickets.