[CentralOH] Unit Testing with PyDev
mark at microenh.com
Mon May 12 04:50:29 CEST 2008
On Sat, 2008-05-10 at 08:13 -0400, Mark Erbaugh wrote:
> I'm using Eclipse with PyDev for Python development. I've written
> several unit test scipts. I can run each one using Eclipse/Pydev's Run
> as Python unit-test command.
> Is there a way to automatically run them all at once? I created a
> simple script that sort of works:
> from Test1 import *
> from Test2 import *
> However, the problem is that I wasn't very creative in naming my test
> cases so Test1 and Test2 may have test cases with the same name, which
> would mean that some test cases may be skipped.
> I've noticed that Run As Python unit-test ignores the code I've placed
> in the if __name__ == '__main__' suite. Apparently, it just looks for
> Test... objects.
Here's a solution I worked up. The MODULES is a list of <str>s of the
test module names. Comments are welcome.
all tests runner for Eclipse
add name of test module as <str> to MODULES
MODULES = (
ct = 0
for i in MODULES:
exec 'import %s as X' % i
for j in dir(X):
if j.find('Test') == 0:
exec 'Test%d = X.%s' % (ct, j)
ct += 1
More information about the CentralOH