forked from ISISNeutronMuon/SScanSS-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_coverage.py
42 lines (31 loc) · 909 Bytes
/
test_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
import sys
import unittest
try:
import coverage
except ImportError:
print('\n"Coverage.py" is required for coverage tests.')
sys.exit(-1)
MIN_COVERAGE = 70
def run_tests_with_coverage():
cov = coverage.Coverage()
cov.erase()
cov.start()
loader = unittest.TestLoader()
tests = loader.discover('tests')
test_runner = unittest.runner.TextTestRunner()
result = test_runner.run(tests)
cov.stop()
cov.save()
if not result.wasSuccessful():
return False
percentage = cov.html_report(omit=['test*', '*__init__*'])
if percentage < MIN_COVERAGE:
err = 'Coverage of {} is below the expected threshold of {}%'.format(percentage, MIN_COVERAGE)
print(err, file=sys.stderr)
return False
return True
if __name__ == '__main__':
success = run_tests_with_coverage()
if success:
sys.exit(0)
sys.exit(1)