-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_coverage_tests.py
executable file
·47 lines (38 loc) · 1.13 KB
/
run_coverage_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
import os
import unittest
import coverage
def set_test_environment():
# Set the environment variable to determine the app configuration
os.environ['CONFIG'] = 'TESTING'
def run_tests():
# Set test environment
set_test_environment()
# Start coverage (exclude unit tests)
cov = coverage.Coverage(omit=["unit_tests/*",
"configuration/*",
"helpers/common_responses.py",
"helpers/input_validator.py",
"helpers/__init__.py",
"application/schemas.py",
"application/__init__.py",
"application/models.py",
"api/__init__.py",])
cov.start()
# Discover and run tests
loader = unittest.TestLoader()
tests = loader.discover('unit_tests')
testRunner = unittest.TextTestRunner()
testRunner.run(tests)
# Stop coverage and save results
cov.stop()
cov.save()
# Report coverage
print("\nCoverage Report:")
cov.report()
# Generate HTML report
cov.html_report(directory='coverage_html_report')
# Generate XML report
cov.xml_report(outfile='coverage.xml')
# Run the tests
if __name__ == '__main__':
run_tests()