forked from symstore/symstore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest
More file actions
executable file
·61 lines (41 loc) · 1.41 KB
/
test
File metadata and controls
executable file
·61 lines (41 loc) · 1.41 KB
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
#!/usr/bin/env python
import sys
import unittest
import argparse
from contextlib import contextmanager
from tests import conf
TESTS_DIR = "tests"
def parse_args():
parser = argparse.ArgumentParser(
description="runs specified tests, "
"or run all discovered tests if no are tests specified")
parser.add_argument("tests", metavar="test", nargs='*',
help="test case to run")
parser.add_argument("--coverage", action="store_true", default=False)
return parser.parse_args()
def get_testsuite(tests):
test_loader = unittest.TestLoader()
if len(tests) == 0:
# no test names specified, run all discovered tests
return test_loader.discover(TESTS_DIR)
test_names = ["%s.%s" % (TESTS_DIR, name) for name in tests]
return test_loader.loadTestsFromNames(test_names)
@contextmanager
def coverage(enabled):
conf.WITH_COVERAGE = enabled
if enabled:
# only import coverage if we actually using
from coverage import Coverage
cov = Coverage(config_file=True, auto_data=True, data_suffix=True)
cov.start()
yield None
cov.stop()
cov.save()
else:
yield None
args = parse_args()
test_suites = get_testsuite(args.tests)
with coverage(args.coverage):
res = unittest.TextTestRunner(verbosity=2).run(test_suites)
if not res.wasSuccessful():
sys.exit(1)