forked from coleifer/huey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtests.py
executable file
·48 lines (37 loc) · 1.37 KB
/
runtests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
import glob
import optparse
import os
import sys
import unittest
from huey import tests
def collect_tests(args=None):
suite = unittest.TestSuite()
if not args:
from huey import tests
module_suite = unittest.TestLoader().loadTestsFromModule(tests)
suite.addTest(module_suite)
else:
tmpl = 'huey.tests.test_%s'
cleaned = [tmpl % arg if not arg.startswith('test') else arg
for arg in args]
user_suite = unittest.TestLoader().loadTestsFromNames(cleaned)
suite.addTest(user_suite)
return suite
def runtests(suite, verbosity=1, failfast=False):
runner = unittest.TextTestRunner(verbosity=verbosity, failfast=failfast)
results = runner.run(suite)
return results.failures, results.errors
if __name__ == '__main__':
parser = optparse.OptionParser()
parser.add_option('-v', '--verbosity', dest='verbosity', default=1,
type='int', help='Verbosity of output')
parser.add_option('-f', '--failfast', action='store_true', default=False,
help='Stop on first failure or error.')
options, args = parser.parse_args()
suite = collect_tests(args)
failures, errors = runtests(suite, options.verbosity, options.failfast)
for f in glob.glob('huey*.db*'):
os.unlink(f)
if errors or failures:
sys.exit(1)