view makeitso/python_package/tests/testall.py @ 192:44bd0cc9bbc3

rename
author Jeff Hammel <k0scist@gmail.com>
date Thu, 08 May 2014 16:55:28 -0700
parents 3cccaa4d48cc
children 41d17337656a
line wrap: on
line source

#!/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()