Mark Pilgrim gives a short but very useful program to run all your tests automatically in . If your testfiles all end in "test.py", this program will import all the classes in these files, make a Test
Suite out of the Test
Cases or Test
Suites they contain, and start unittest with that Test
Suite. I call this program 'Test
Runner.py':
- """Regression testing framework
-
This module will search for scripts in the same directory named
-
XYZTest.py. Each such script should be a test suite that tests a
-
module through PyUnit. (As of Python 2.1, PyUnit is included in
-
the standard library as "unittest".) This script will aggregate all
-
found test suites into one big test suite and run them all at once.
-
"""
-
-
import unittest
-
-
import sys, os, re, unittest
-
-
def regressionTest():
-
path = os.path.split(sys.argv[0])[0] or os.getcwd()
-
files = os.listdir(path)
-
test = re.compile("test.py$", re.IGNORECASE)
-
files = filter(test.search, files)
-
filenameToModuleName = lambda f: os.path.splitext(f)[0]
-
moduleNames = map(filenameToModuleName, files)
-
modules = map(__import__, moduleNames)
-
load = unittest.defaultTestLoader.loadTestsFromModule
-
return unittest.TestSuite(map(load, modules))
-
-
if __name__ == "__main__":
-
unittest.main(defaultTest="regressionTest")
阅读(761) | 评论(0) | 转发(0) |