forked from Zipfian-Science/rickled
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_tests.py
80 lines (72 loc) · 2.51 KB
/
run_tests.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import argparse
import unittest
import coverage
def specified_tests(tests):
for test in tests:
file_name = '%s.py' % test
tests = unittest.TestLoader().discover(start_dir="./tests/unittest", pattern=file_name, top_level_dir=".")
unittest.TextTestRunner(verbosity=4).run(tests)
tests = unittest.TestLoader().discover(start_dir="./tests/integration", pattern=file_name, top_level_dir=".")
unittest.TextTestRunner(verbosity=4).run(tests)
def all_unit_tests(do_coverage=False):
cov = coverage.Coverage(cover_pylib=False, data_file='.unittest')
if do_coverage:
cov.start()
tests = unittest.TestLoader().discover(start_dir="./tests/unittest", pattern="test_*.py", top_level_dir=".")
result = unittest.TextTestRunner(verbosity=4).run(tests)
if do_coverage:
cov.stop()
cov.save()
cov.html_report(directory='coverage_report/unittests')
return result.wasSuccessful()
def all_integration_tests(do_coverage=False):
cov = coverage.Coverage(cover_pylib=False, data_file='.integration')
if do_coverage:
cov.start()
tests = unittest.TestLoader().discover(start_dir="./tests/integration", pattern="test_*.py", top_level_dir=".")
result = unittest.TextTestRunner(verbosity=4).run(tests)
if do_coverage:
cov.stop()
cov.save()
cov.html_report(directory='coverage_report/integration')
return result.wasSuccessful()
def main(args):
if args.tests:
specified_tests(args.tests)
if args.unit:
all_unit_tests(args.coverage)
if args.integration:
all_integration_tests(args.coverage)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description="""
Runs tests for Pickle Rick including unit, integration, and coverage tests.
""",
)
parser.add_argument(
"--unit",
"-u",
help="Run all unit tests",
action="store_true",
)
parser.add_argument(
"--integration",
"-i",
help="Run all integration tests",
action="store_true",
)
parser.add_argument(
"--coverage",
"-c",
help="Run coverage over selected tests",
action="store_true",
default=False
)
parser.add_argument(
'-t',
'--tests',
nargs='+',
help='Define a list of python test files to run, Usage: python run_tests.py -t test_data test_utils'
)
main(parser.parse_args())