Mercurial > hg > MakeItSo
changeset 191:3cccaa4d48cc
add unittest runner
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Thu, 08 May 2014 16:54:58 -0700 |
parents | 7f48c1e2f523 |
children | 44bd0cc9bbc3 |
files | makeitso/python_package/tests/testall.py |
diffstat | 1 files changed, 36 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/makeitso/python_package/tests/testall.py Thu May 08 16:54:58 2014 -0700 @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +""" +run all unit tests +""" + +import os +import sys +import unittest + +here = os.path.dirname(os.path.abspath(__file__)) + +def main(args=sys.argv[1:]): + + results = unittest.TestResult() + suite = unittest.TestLoader().discover(here, 'test_*.py') + suite.run(results) + n_errors = len(results.errors) + n_failures = len(results.failures) + print ("Run {} tests ({} failures; {} errors)".format(results.testsRun, + n_failures, + n_errors)) + if results.wasSuccessful(): + print ("Success") + sys.exit(0) + else: + if n_failures: + print (results.failures) + if n_errors: + print (results.errors) + results.printErrors() + sys.exit(1) + +if __name__ == '__main__': + main() +