diff --git a/discover_jenkins/settings.py b/discover_jenkins/settings.py index 942569b..64f3181 100644 --- a/discover_jenkins/settings.py +++ b/discover_jenkins/settings.py @@ -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) diff --git a/discover_jenkins/tasks/with_coverage.py b/discover_jenkins/tasks/with_coverage.py index 0fdcf79..2fd8b40 100755 --- a/discover_jenkins/tasks/with_coverage.py +++ b/discover_jenkins/tasks/with_coverage.py @@ -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 diff --git a/docs/tasks.rst b/docs/tasks.rst index 0a681fd..df67d44 100644 --- a/docs/tasks.rst +++ b/docs/tasks.rst @@ -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::