Allow specifying which unit-tests to run
authorThomas Leonard <talex5@gmail.com>
Fri, 29 Apr 2011 15:49:13 +0000 (29 16:49 +0100)
committerThomas Leonard <talex5@gmail.com>
Fri, 29 Apr 2011 15:49:13 +0000 (29 16:49 +0100)
e.g. 0test ../0release.xml -- testrelease.TestRelease.testBinaryRelease

tests/testall.py

index 9cb4bb3..d674eb4 100755 (executable)
@@ -11,18 +11,22 @@ my_dir = os.path.dirname(sys.argv[0])
 if not my_dir:
        my_dir = os.getcwd()
 
-sys.argv.append('-v')
+testLoader = unittest.TestLoader()
 
-suite_names = [f[:-3] for f in os.listdir(my_dir)
-               if f.startswith('test') and f.endswith('.py')]
-suite_names.remove('testall')
-suite_names.sort()
+if len(sys.argv) > 1:
+       alltests = testLoader.loadTestsFromNames(sys.argv[1:])
+else:
+       alltests = unittest.TestSuite()
 
-alltests = unittest.TestSuite()
+       suite_names = [f[:-3] for f in os.listdir(my_dir)
+                       if f.startswith('test') and f.endswith('.py')]
+       suite_names.remove('testall')
+       suite_names.sort()
 
-for name in suite_names:
-       m = __import__(name, globals(), locals(), [])
-       alltests.addTest(m.suite)
+       for name in suite_names:
+               m = __import__(name, globals(), locals(), [])
+               t = testLoader.loadTestsFromModule(m)
+               alltests.addTest(t)
 
 a = unittest.TextTestRunner(verbosity=2).run(alltests)