-
Notifications
You must be signed in to change notification settings - Fork 8
/
test_with_coverage.py
37 lines (27 loc) · 964 Bytes
/
test_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
import coverage
import unittest
# Start coverage
cov = coverage.Coverage()
cov.start()
# Load the specific test case
# test_suite = unittest.defaultTestLoader.loadTestsFromName('tests.test_serializer.TestSerialization')
# Discover and run tests in "test" dir
test_suite = unittest.TestLoader().discover(start_dir="tests")
test_runner = unittest.TextTestRunner(verbosity=2, failfast=True)
result = test_runner.run(test_suite)
# Stop and save coverage data
try:
cov.stop()
except AssertionError:
# cov.stop() sometimes fails even though it saved the coverage data
# Not sure what's the actual cause, but this is a hackaround
# It probably has something to do with multiprocessing, and not killing
# blender/nrn processes gracefully at end of each unit test
pass
cov.save()
# Report the coverage results
cov.html_report(directory="htmlcov")
cov.report()
# Exit with appropriate status code
if not result.wasSuccessful():
exit(1)