[Pyunit-interest] improved alltests.py example
Brought to you by:
purcell
From: Jean C. <j4...@ya...> - 2002-12-17 18:09:07
|
I am writing to suggest a minor-- but important-- improvement in the file alltests.py file in the examples folder. The modules_to_test should be a true list with square brackets. As it is, if you have just one module, the map function following it will iterate over the letters in the string that is the module name rather than seeing it as a list with one string element. For example, modules_to_test = ('widgettests') map(__import__, modules_to_test) results in the error ImportError: No module named w The original code and my suggested change are shown below. By the way, is my terminology correct? What do you call it with the curved brackets? Thanks, Jean ------------------------------------------------ original code for alltests.py import unittest def suite(): modules_to_test = ('listtests', 'widgettests') # and so on alltests = unittest.TestSuite() for module in map(__import__, modules_to_test): alltests.addTest(unittest.findTestCases(module)) return alltests if __name__ == '__main__': unittest.main(defaultTest='suite') ------------------------------------------------ improved code for alltests.py import unittest def suite(): modules_to_test = ['listtests', 'widgettests'] # and so on <=== change is here: square brackets instead of rounded alltests = unittest.TestSuite() for module in map(__import__, modules_to_test): alltests.addTest(unittest.findTestCases(module)) return alltests if __name__ == '__main__': unittest.main(defaultTest='suite') __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com |