-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_tests_with_coverage.py
48 lines (39 loc) · 1.24 KB
/
run_tests_with_coverage.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 sys
import os
import re
import unittest
from coverage import coverage as Coverage
from log import logger
import argparse
if __name__ == '__main__':
arg_parser = argparse.ArgumentParser(description="""
This script runs all test and show coverage with Coverage""")
arg_parser.add_argument(
'-hr', '--html-report',
help='Directory save htmlreport to'
)
args = arg_parser.parse_args()
def main():
list_of_test_files = list()
for directory in os.walk('.'):
for filename in directory[2]:
if re.search(".*_tests?\.py", filename):
list_of_test_files.append(filename)
list_of_test_files.append('config_testing.py')
coverage = Coverage(omit=list_of_test_files)
list_of_test_files.pop()
coverage.start()
# no log messages
logger.setLevel(1000000000000)
loader = unittest.TestLoader()
suite = loader.discover('.', '*_test.py')
test_runner = unittest.TextTestRunner(verbosity=2)
test_result = test_runner.run(suite)
coverage.stop()
coverage.report(file=sys.stdout)
if args.html_report:
coverage.html_report(directory=args.html_report)
print(test_result)
if __name__ == '__main__':
main()