[TIP] fresh fixture on module functions

Nate Lowrie solodex2151 at gmail.com
Sun Mar 4 15:31:00 PST 2007


I am currently writing unit tests for the dabo framework.  I have run
into a test smell that I don't quite know how to approach.  I have
several functions defined in a file called dColors. So, it would be:
-----------------------
def a():
  do something...

def b():
  do something else...

etc.
-------------------------

When I am testing I do import dColors at the beginning.  All of the
functions are calculation functions so they could be easily tested.
However, I noticed that there was a Fragile Test smell due to a
persistent fixture.  I wanted to stub some of the module functions out
so that I can do behavior verification on one function and avoid
repeated test code.  However, I can't figure out how to get a fresh
fixture and broke some of the test when I tried to do behavior
verification.

I tried the copy module, re-importing the module, storing a copy in a
separate namespace.  Nothing has worked.  So, I have 2 questions:

1) Am I mistaken that this is a test smell and a major problem?

2) Is there anyway that I can fix it without putting the functions in
a class?  More important, if the persistent fixture is a problem, does
that mean to design for testability we have to put all functions in
classes to solve the problem?

Using unittest for testing.  Tests can be found by grabbing
ftp://dabodev.com/dabo/dabo.nightly.tar.gz and looking under the tests
folder.

Thanks for the help on this.

Nate Lowrie



More information about the testing-in-python mailing list