Getting PyUnit to run Package Test Modules

Casey McGinty casey.mcginty at gmail.com
Tue Apr 22 06:12:40 EDT 2008


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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080422/43aee75c/attachment.html>


More information about the Python-list mailing list