[TIP] Testing the Fixture?

Pete pfein at pobox.com
Wed Nov 21 06:59:11 PST 2007


Hi all-

Any suggestions on how to write tests where the fixture gets tested as well?

A little background:
My library is a data storage service, so the load-the-data operation should 
probably get tested.  However, that operation is also the fixture for 
subsequent tests, which retrieve/search/delete/etc..

I've got 2 problems:
Structuring the tests w/o code duplication is difficult, because I don't want 
to run the fixture for test_load().  I can probably work around this by 
abstracting the guts of the fixture/test_load() into a do_load() method on a 
base class and then using 2 subclasses, but eww.

The second problem is that I'd like the subsequent tests to be run only if the 
test for the fixture passes, since they're dependent on successfully loading 
the data to begin with.  I dunno what the theory/best practice for this sort 
of contingent test is... do you just let the dependent tests fail and clutter 
up the screen with the same traceback half a dozen times?

Sorry if this makes no sense. Oh, I'm using nose btw.

-- 
Peter Fein   ||   773-575-0694   ||   pfein at pobox.com
http://www.pobox.com/~pfein/   ||   PGP: 0xCCF6AE6B
irc: pfein at freenode.net   ||   jabber: peter.fein at gmail.com



More information about the testing-in-python mailing list