I came up with this solution based off of the __import__ python reference page. If I missed anything let me know.
def suite(): # create TestSuite object alltests = unittest.TestSuite() # load all modules define in the module list for name in mod_to_test: print name mod = __import__(name) components = name.split('.') for comp in components[1:]: print comp mod = getattr(mod,comp) alltests.addTest(unittest.findTestCases(mod)) return alltest On Tue, Apr 22, 2008 at 12:12 AM, Casey McGinty <[EMAIL PROTECTED]> wrote: > Hopefully this is an easy question for someone to answer. I have a > directory structure like so: > > alltest.py > prog.py > ../package > __init__.py > mod1.py > test_mod1.py > modn. py > (and so on...) > > Each test_mod*.py file contains some PyUnit test cases. I am using the > following code in alltest.py to run all the unit test modules: > > mod_to_test = [package.mod1, package.mod2] > > def suite(): > # create TestSuite object > alltests = unittest.TestSuite() > # load all modules define in the module list > for module in map(__import__, mod_to_test): > alltests.addTest(unittest.findTestCases(module)) > return alltest > > if __name__ == '__main__': > unittest.main(defaultTest='suite') > > My guess is there is something needed in __init__.py to get this work. Any > advice? > >
-- http://mail.python.org/mailman/listinfo/python-list