[omaha] django and testing

Mike Hostetler mike at squarepegsystems.com
Tue Feb 12 17:53:41 CET 2013


I meant to do reply yesterday, but didn't get to it.

I use a combination of fixtures and lists/mock objects (i.e. objects that
look like my models, but are objects that I created myself).  I actually
prefer the mock objects -- I have more control, I don't have to create and
destroy a database each time. But sometimes fixtures are easier -- it's
easy to take a snapshot of your existing data, especially if it's in the
"troublesome" state  and then start writing tests to figure out what is
wrong.

I also try to have a strong delineation between my Django application (the
view and save) and the "real work". I really try to have little logic in my
views but designate that to other functions and classes that may nor may
not know anything about Django. Generally they just accept some objects,
check the state of said objects, and create an object and send it back. The
calling class is responsible for the persistence. How successful I am on
that goal is a good question. ;) But doing work like that does making
writing tests easier, because you have less database work to deal with.

My $0.02 . . .


On Sun, Feb 10, 2013 at 7:56 PM, Jeff Hinrichs - DM&T <jeffh at dundeemt.com>wrote:

> Is anyone on the list using factories instead of fixtures for django
> testing?
>
> Was watching a pycon video
> https://pycon-2012-notes.readthedocs.org/en/latest/testing_and_django.html#
> and the presenter talked about burning fixtures and use factories,
> specifically factory_boy, instead.
>
> It sounds really nice as the pain points it stops, broken fixtures do to db
> migrations and ease of creating test data -- both of which I've dealt with
> recently.
>
> I've been kicking the tires and testing the approach out a bit. I've liked
> what I've found so much that I wrote a script to turn fixtures into
> factories, https://bitbucket.org/dundeemt/fixture_to_factory
>
> I'm looking for any wisdom others might have, who have more experience with
> this method.  Gotch'yas, factory layout and integration in the django
> structure, etc.
>
>
> --
> Best,
>
> Jeff Hinrichs
> 402.218.1473
> _______________________________________________
> Omaha Python Users Group mailing list
> Omaha at python.org
> http://mail.python.org/mailman/listinfo/omaha
> http://www.OmahaPython.org
>



-- 
Mike Hostetler
SquarePeg Systems
http://www.squarepegsystems.com


More information about the Omaha mailing list