comparison makeitso/python_package/tests/testall.py @ 191:3cccaa4d48cc

add unittest runner
author Jeff Hammel <k0scist@gmail.com>
date Thu, 08 May 2014 16:54:58 -0700
parents
children 41d17337656a
comparison
equal deleted inserted replaced
190:7f48c1e2f523 191:3cccaa4d48cc
1 #!/usr/bin/env python
2
3 """
4 run all unit tests
5 """
6
7 import os
8 import sys
9 import unittest
10
11 here = os.path.dirname(os.path.abspath(__file__))
12
13 def main(args=sys.argv[1:]):
14
15 results = unittest.TestResult()
16 suite = unittest.TestLoader().discover(here, 'test_*.py')
17 suite.run(results)
18 n_errors = len(results.errors)
19 n_failures = len(results.failures)
20 print ("Run {} tests ({} failures; {} errors)".format(results.testsRun,
21 n_failures,
22 n_errors))
23 if results.wasSuccessful():
24 print ("Success")
25 sys.exit(0)
26 else:
27 if n_failures:
28 print (results.failures)
29 if n_errors:
30 print (results.errors)
31 results.printErrors()
32 sys.exit(1)
33
34 if __name__ == '__main__':
35 main()
36