comparison tests/testall.py @ 0:e58db0f06ed8

initial commit (stub)
author Jeff Hammel <k0scist@gmail.com>
date Tue, 27 Jan 2015 14:01:52 -0800
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e58db0f06ed8
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 # print failures and errors
28 for label, item in (('FAIL', results.failures),
29 ('ERROR', results.errors)):
30 if item:
31 print ("\n{}::\n".format(label))
32 for index, (i, message) in enumerate(item):
33 print ('{}) {}:'.format(index, str(i)))
34 print (message)
35 sys.exit(1)
36
37 if __name__ == '__main__':
38 main()
39
40