unittest: collecting tests from many modules?

Jorgen Grahn jgrahn-nntq at algonet.se
Mon Jul 4 11:20:37 EDT 2005


On 12 Jun 2005 10:14:50 GMT, Jorgen Grahn <jgrahn-nntq at algonet.se> wrote:

[regarding module unittest]

> What's the best way of creating a test.py which
> - aggregates the tests from all the test_*.py modules?
> - doesn't require me to enumerate all the test classes in test.py
>   (forcing each module to define test_foo.theSuite or someting would
>   be OK though)
> - retains the ability to select tests and verbosity (-q, -v) from the
>   command line?

Thanks for all the input. Three weeks later I stumble across this thread
again and notice I didn't report what I ended up with.  I ended up doing the
thing I wanted to avoid in the first place: hardcoding everything.

import unittest

import test_bibdb
import test_citefmt
import test_person
import test_refsfmt

suite = unittest.TestSuite()
suite.addTest(test_bibdb.suite())
suite.addTest(test_citefmt.suite())
suite.addTest(test_person.suite())
suite.addTest(test_refsfmt.suite())

if __name__ == "__main__":
    unittest.TextTestRunner(verbosity=2).run(suite)

My test modules are, after all, a fairly fixed set, and if I want to run
specific tests, or with a specific verbosity, I can execute the individual
test modules.

BR,
/Jorgen

-- 
  // Jorgen Grahn <jgrahn@       Ph'nglui mglw'nafh Cthulhu
\X/                algonet.se>   R'lyeh wgah'nagl fhtagn!



More information about the Python-list mailing list