Created
March 27, 2012 10:52
-
-
Save lcc-321/2214822 to your computer and use it in GitHub Desktop.
pyunit test all
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python2.6 | |
| # -*- coding: utf-8 -*- | |
| import sys, os, re, unittest | |
| test = re.compile("test\.py$", re.IGNORECASE) | |
| def get_test_files(dir, files): | |
| """ recursion search test module | |
| Args: dir: search root directory, files: result container """ | |
| for file in os.listdir(dir): | |
| file = os.path.join(dir, file) | |
| if os.path.isdir(file): | |
| get_test_files(file, files) | |
| if test.search(file): | |
| files.append(file) | |
| def import_file(file): | |
| syspath = sys.path[0] | |
| sys.path[0] = os.path.dirname(file) | |
| module = __import__(os.path.splitext(os.path.basename(file))[0]); | |
| sys.path[0] = syspath | |
| return module | |
| def regression_test(): | |
| files = []; get_test_files(os.getcwd(), files) | |
| modules = map(import_file, files) | |
| load = unittest.defaultTestLoader.loadTestsFromModule | |
| return unittest.TestSuite(map(load, modules)) | |
| if __name__ == "__main__": | |
| unittest.main(defaultTest="regression_test") | |
| os.remove(os.path.join(os.getcwd(), "test.log")) | |
| os.remove(os.path.join(os.getcwd(), "nohup.out")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment