comparison tests/testall.py @ 0:a05c70cc24be

initial commit
author Jeff Hammel <k0scist@gmail.com>
date Fri, 31 Mar 2017 18:21:15 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:a05c70cc24be
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