-
Notifications
You must be signed in to change notification settings - Fork 238
Expand file tree
/
Copy pathtest_utils.py
More file actions
31 lines (24 loc) · 1.14 KB
/
test_utils.py
File metadata and controls
31 lines (24 loc) · 1.14 KB
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
# -*- coding: utf-8 -*-
from django.conf import settings
from django.test.simple import DjangoTestSuiteRunner
import coverage
class CoverageRunner(DjangoTestSuiteRunner):
def run_tests(self, *args, **kwargs):
run_with_coverage = hasattr(settings, 'COVERAGE_MODULES')
if run_with_coverage:
coverage.use_cache(0)
coverage.start()
result = super(CoverageRunner, self).run_tests(*args, **kwargs)
if run_with_coverage:
coverage.stop()
print ''
print '----------------------------------------------------------------------'
print ' Unit Test Code Coverage Results'
print '----------------------------------------------------------------------'
coverage_modules = []
for module in settings.COVERAGE_MODULES:
coverage_modules.append(__import__(module, globals(),
locals(), ['']))
coverage.report(coverage_modules, show_missing=1)
print '----------------------------------------------------------------------'
return result