mirror of
https://github.com/jazzband/django-discover-jenkins.git
synced 2026-05-15 02:55:02 +00:00
Make coverage works and exclude files
This commit is contained in:
parent
d074b54b57
commit
18b35ffdca
3 changed files with 20 additions and 38 deletions
|
|
@ -12,8 +12,7 @@ PROJECT_APPS = getattr(settings, 'TEST_PROJECT_APPS', ())
|
|||
COVERAGE_WITH_MIGRATIONS = getattr(settings, 'TEST_COVERAGE_WITH_MIGRATIONS', False)
|
||||
COVERAGE_REPORT_HTML_DIR = getattr(settings, 'TEST_COVERAGE_REPORT_HTML_DIR', '')
|
||||
COVERAGE_MEASURE_BRANCH = getattr(settings, 'TEST_COVERAGE_MEASURE_BRANCH', True)
|
||||
COVERAGE_EXCLUDES = getattr(settings, 'TEST_COVERAGE_EXCLUDES', [])
|
||||
COVERAGE_EXCLUDES_FOLDERS = getattr(settings, 'TEST_COVERAGE_EXCLUDES_FOLDERS', [])
|
||||
COVERAGE_EXCLUDE_PATHS = getattr(settings, 'TEST_COVERAGE_EXCLUDE_PATHS', [])
|
||||
COVERAGE_RCFILE = getattr(settings, 'TEST_COVERAGE_RCFILE', 'coverage.rc')
|
||||
|
||||
JSHINT_CHECKED_FILES = getattr(settings, 'TEST_JSHINT_CHECKED_FILES', None)
|
||||
|
|
|
|||
|
|
@ -49,9 +49,9 @@ class CoverageTask(object):
|
|||
make_option(
|
||||
"--coverage-exclude",
|
||||
action="append",
|
||||
default=settings.COVERAGE_EXCLUDES,
|
||||
default=settings.COVERAGE_EXCLUDE_PATHS,
|
||||
dest="coverage_excludes",
|
||||
help="Module name to exclude"
|
||||
help="Paths to be excluded from coverage"
|
||||
)
|
||||
)
|
||||
|
||||
|
|
@ -61,21 +61,7 @@ class CoverageTask(object):
|
|||
self.html_dir = options['coverage_html_report_dir']
|
||||
self.branch = options['coverage_measure_branch']
|
||||
|
||||
self.exclude_locations = []
|
||||
modnames = options['coverage_excludes']
|
||||
for modname in modnames:
|
||||
try:
|
||||
self.exclude_locations.append(
|
||||
os.path.dirname(
|
||||
import_module(modname).__file__
|
||||
)
|
||||
)
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
# Extra folders to exclude. Particularly useful to specify things like
|
||||
# apps/company/migrations/*
|
||||
self.exclude_locations.extend(settings.COVERAGE_EXCLUDES_FOLDERS)
|
||||
self.exclude_locations = options['coverage_excludes'] or None
|
||||
|
||||
self.coverage = coverage(
|
||||
branch=self.branch,
|
||||
|
|
@ -89,24 +75,27 @@ class CoverageTask(object):
|
|||
|
||||
def teardown_test_environment(self, **kwargs):
|
||||
self.coverage.stop()
|
||||
self.coverage._harvest_data()
|
||||
|
||||
morfs = [filename for filename in self.coverage.data.measured_files()
|
||||
if self.want_file(filename)]
|
||||
|
||||
if not os.path.exists(self.output_dir):
|
||||
os.makedirs(self.output_dir)
|
||||
self.coverage.xml_report(morfs=morfs,
|
||||
outfile=os.path.join(
|
||||
self.output_dir, 'coverage.xml'))
|
||||
|
||||
self.coverage.xml_report(
|
||||
morfs=morfs,
|
||||
outfile=os.path.join(self.output_dir, 'coverage.xml')
|
||||
)
|
||||
|
||||
if self.html_dir:
|
||||
self.coverage.html_report(morfs=morfs, directory=self.html_dir)
|
||||
self.coverage.html_report(
|
||||
morfs=morfs,
|
||||
directory=self.html_dir
|
||||
)
|
||||
|
||||
def want_file(self, filename):
|
||||
if not self.with_migrations and '/migrations/' in filename:
|
||||
return False
|
||||
for location in self.exclude_locations:
|
||||
if filename.startswith(location):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -39,25 +39,19 @@ Settings
|
|||
|
||||
TEST_COVERAGE_MEASURE_BRANCH = True
|
||||
|
||||
* ``TEST_COVERAGE_EXCLUDES``
|
||||
* ``TEST_COVERAGE_EXCLUDE_PATHS``
|
||||
|
||||
Module names to exclude.
|
||||
File paths to exclude. Can be myapp/admin.py or myapp/management/*
|
||||
|
||||
Default value::
|
||||
|
||||
TEST_COVERAGE_EXCLUDES = []
|
||||
|
||||
* ``TEST_COVERAGE_EXCLUDES_FOLDERS``
|
||||
|
||||
Extra folders to exclude.
|
||||
|
||||
Default value::
|
||||
|
||||
TEST_COVERAGE_EXCLUDES_FOLDERS = []
|
||||
TEST_COVERAGE_EXCLUDE_PATHS = []
|
||||
|
||||
* ``TEST_COVERAGE_RCFILE``
|
||||
|
||||
Specify configuration file.
|
||||
Specify configuration file. Please note if you set the ``TEST_COVERAGE_EXCLUDE_PATHS``
|
||||
setting, coverage will ignore your coverage.rc file. So if you want to customize
|
||||
coverage settings only use this file and not the other settings.
|
||||
|
||||
Default value::
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue