forked from potassco/clorm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtests.py
executable file
·65 lines (49 loc) · 1.59 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
import optparse
import os
import shutil
import sys
import unittest
USER = os.environ.get("USER") or "root"
def runtests(suite, verbosity=1, failfast=False):
runner = unittest.TextTestRunner(verbosity=verbosity, failfast=failfast)
results = runner.run(suite)
return results.failures, results.errors
def get_option_parser():
usage = "usage: %prog module1, module2 ..."
parser = optparse.OptionParser(usage=usage)
basic = optparse.OptionGroup(parser, "Basic test options")
basic.add_option(
"-v", "--verbosity", dest="verbosity", default=1, type="int", help="Verbosity of output"
)
basic.add_option(
"-f",
"--failfast",
action="store_true",
default=False,
dest="failfast",
help="Exit on first failure/error.",
)
parser.add_option_group(basic)
return parser
def collect_tests(args):
suite = unittest.TestSuite()
if not args:
import tests
module_suite = unittest.TestLoader().loadTestsFromModule(tests)
suite.addTest(module_suite)
else:
cleaned = ["tests.%s" % arg if not arg.startswith("tests.") else arg for arg in args]
user_suite = unittest.TestLoader().loadTestsFromNames(cleaned)
suite.addTest(user_suite)
return suite
if __name__ == "__main__":
parser = get_option_parser()
options, args = parser.parse_args()
suite = collect_tests(args)
failures, errors = runtests(suite, options.verbosity, options.failfast)
if errors:
sys.exit(2)
elif failures:
sys.exit(1)
sys.exit(0)