Organising unit tests

jimburton jimburton1 at gmail.com
Fri Sep 29 06:45:41 EDT 2006


I have a number of unit tests organised hierarchically, all of which
inherit fixtures from a base class. To run these all at once I started
out using

from basic import map, directionalpan, layerorder, layervisibility,
listlayers, streamlayerlist
# ... lots more ...

suite0 =
unittest.TestLoader().loadTestsFromTestCase(directionalpan.TestPan)
suite1 =
unittest.TestLoader().loadTestsFromTestCase(layerorder.TestLayerorder)
# ... lots more ...

alltests = unittest.TestSuite([suite0
                               , suite1
                               ....])
unittest.TextTestRunner(verbosity=2).run(alltests)

Which is unmaintainable. the TestLoader docs warn that
loadTestsFromModule will not play nicely with my situation and indeed
if I try

suite0 = unittest.TestLoader().loadTestsFromModule(basic)

then run the tests, it hasn't picked any up. I suppose I could collect
and run the tests with a shell script...what are my options here to
avoid hardcoding and maintaining the list of tests, and how is it
normally done?

Thanks.




More information about the Python-list mailing list