Look at the unittest.TestLoader (http://www.python.org/doc/2.5.2/lib/testloader-objects.html)
And the os.walk (http://www.python.org/doc/2.5.2/lib/os-file-dir.html)
You should be able to traverse your package tree using the TestLoader to build a suite which you can then run.
Something along the lines of this.
runner = unittest.TextTestRunner()
superSuite = unittest.TestSuite()
for path, dirs, files in os.walk( 'path/to/tree' ):
# if a CVS dir or whatever: continue
for f in files:
# if not a python file: continue
suite= unittest.defaultTestLoader.loadTestsFromModule( os.path.join(path,f)
superSuite .addTests(suite ) # OR runner.run( suite)
runner.run( superSuite )
You can either walk through the tree simply running each test (runner.run(suite)
) or you can accumulate a superSuite
of all individual suites and run the whole mass as a single test (runner.run( superSuite )
).
You don't need to do both, but I included both sets of suggestions in the above (untested) code.