diff options
-rw-r--r-- | coverage/config.py | 27 | ||||
-rw-r--r-- | coverage/control.py | 17 | ||||
-rw-r--r-- | coverage/report.py | 8 | ||||
-rw-r--r-- | doc/config.rst | 6 | ||||
-rw-r--r-- | doc/source.rst | 3 | ||||
-rw-r--r-- | tests/test_api.py | 7 | ||||
-rw-r--r-- | tests/test_config.py | 13 | ||||
-rw-r--r-- | tests/test_debug.py | 3 |
8 files changed, 59 insertions, 25 deletions
diff --git a/coverage/config.py b/coverage/config.py index 11b7056e..d4d320b0 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -178,6 +178,10 @@ class CoverageConfig(object): self.attempted_config_files = [] self.config_files = [] + # Defaults for [run] and [report] + self._include = None + self._omit = None + # Defaults for [run] self.branch = False self.concurrency = None @@ -189,14 +193,16 @@ class CoverageConfig(object): self.parallel = False self.plugins = [] self.source = None + self.run_include = None + self.run_omit = None self.timid = False # Defaults for [report] self.exclude_list = DEFAULT_EXCLUDE[:] self.fail_under = 0 self.ignore_errors = False - self.include = None - self.omit = None + self.report_include = None + self.report_omit = None self.partial_always_list = DEFAULT_PARTIAL_ALWAYS[:] self.partial_list = DEFAULT_PARTIAL[:] self.precision = 0 @@ -218,7 +224,8 @@ class CoverageConfig(object): # Options for plugins self.plugin_options = {} - MUST_BE_LIST = ["concurrency", "debug", "disable_warnings", "include", "omit", "plugins"] + MUST_BE_LIST = ["run_omit", "run_include", "report_omit", "report_include", + "debug", "plugins", "concurrency"] def from_args(self, **kwargs): """Read config values from `kwargs`.""" @@ -315,9 +322,9 @@ class CoverageConfig(object): ('data_file', 'run:data_file'), ('debug', 'run:debug', 'list'), ('disable_warnings', 'run:disable_warnings', 'list'), - ('include', 'run:include', 'list'), + ('_include', 'run:include', 'list'), ('note', 'run:note'), - ('omit', 'run:omit', 'list'), + ('_omit', 'run:omit', 'list'), ('parallel', 'run:parallel', 'boolean'), ('plugins', 'run:plugins', 'list'), ('source', 'run:source', 'list'), @@ -327,8 +334,8 @@ class CoverageConfig(object): ('exclude_list', 'report:exclude_lines', 'regexlist'), ('fail_under', 'report:fail_under', 'int'), ('ignore_errors', 'report:ignore_errors', 'boolean'), - ('include', 'report:include', 'list'), - ('omit', 'report:omit', 'list'), + ('_include', 'report:include', 'list'), + ('_omit', 'report:omit', 'list'), ('partial_always_list', 'report:partial_branches_always', 'regexlist'), ('partial_list', 'report:partial_branches', 'regexlist'), ('precision', 'report:precision', 'int'), @@ -459,6 +466,12 @@ def read_coverage_config(config_file, **kwargs): if config_read: break + for attr in ('_omit', '_include'): + value = getattr(config, attr) + if value is not None: + for section in ('run', 'report'): + setattr(config, section + attr, value) + # 3) from environment variables: env_data_file = os.environ.get('COVERAGE_FILE') if env_data_file: diff --git a/coverage/control.py b/coverage/control.py index 2cbe491b..c2fe806c 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -143,7 +143,8 @@ class Coverage(object): config_file=config_file, data_file=data_file, cover_pylib=cover_pylib, timid=timid, branch=branch, parallel=bool_or_none(data_suffix), - source=source, omit=omit, include=include, debug=debug, + source=source, run_omit=omit, run_include=include, debug=debug, + report_omit=omit, report_include=include, concurrency=concurrency, ) @@ -235,8 +236,8 @@ class Coverage(object): self.source_pkgs.append(src) self.source_pkgs_unmatched = self.source_pkgs[:] - self.omit = prep_patterns(self.config.omit) - self.include = prep_patterns(self.config.include) + self.omit = prep_patterns(self.config.run_omit) + self.include = prep_patterns(self.config.run_include) concurrency = self.config.concurrency or [] if "multiprocessing" in concurrency: @@ -346,6 +347,8 @@ class Coverage(object): if self.pylib_paths: self.pylib_match = TreeMatcher(self.pylib_paths) if self.include: + if self.source or self.source_pkgs: + print("--include is ignored because --source is set") self.include_match = FnmatchMatcher(self.include) if self.omit: self.omit_match = FnmatchMatcher(self.omit) @@ -1029,7 +1032,7 @@ class Coverage(object): """ self.get_data() self.config.from_args( - ignore_errors=ignore_errors, omit=omit, include=include, + ignore_errors=ignore_errors, report_omit=omit, report_include=include, show_missing=show_missing, skip_covered=skip_covered, ) reporter = SummaryReporter(self, self.config) @@ -1051,7 +1054,7 @@ class Coverage(object): """ self.get_data() self.config.from_args( - ignore_errors=ignore_errors, omit=omit, include=include + ignore_errors=ignore_errors, report_omit=omit, report_include=include ) reporter = AnnotateReporter(self, self.config) reporter.report(morfs, directory=directory) @@ -1078,7 +1081,7 @@ class Coverage(object): """ self.get_data() self.config.from_args( - ignore_errors=ignore_errors, omit=omit, include=include, + ignore_errors=ignore_errors, report_omit=omit, report_include=include, html_dir=directory, extra_css=extra_css, html_title=title, skip_covered=skip_covered, ) @@ -1103,7 +1106,7 @@ class Coverage(object): """ self.get_data() self.config.from_args( - ignore_errors=ignore_errors, omit=omit, include=include, + ignore_errors=ignore_errors, report_omit=omit, report_include=include, xml_output=outfile, ) file_to_close = None diff --git a/coverage/report.py b/coverage/report.py index 609dc2de..b4608633 100644 --- a/coverage/report.py +++ b/coverage/report.py @@ -54,12 +54,12 @@ class Reporter(object): """ reporters = self.coverage._get_file_reporters(morfs) - if self.config.include: - matcher = FnmatchMatcher(prep_patterns(self.config.include)) + if self.config.report_include: + matcher = FnmatchMatcher(prep_patterns(self.config.report_include)) reporters = [fr for fr in reporters if matcher.match(fr.filename)] - if self.config.omit: - matcher = FnmatchMatcher(prep_patterns(self.config.omit)) + if self.config.report_omit: + matcher = FnmatchMatcher(prep_patterns(self.config.report_omit)) reporters = [fr for fr in reporters if not matcher.match(fr.filename)] self._file_reporters = sorted(reporters) diff --git a/doc/config.rst b/doc/config.rst index a8005a4f..75803bd5 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -136,7 +136,8 @@ warning. See :ref:`cmd_warnings` for specific warnings. --debug option <cmd_run_debug>` for details. ``include`` (multi-string): a list of file name patterns, the files to include -in measurement or reporting. See :ref:`source` for details. +in measurement or reporting. Ignored if ``source`` is set. See :ref:`source` +for details. ``note`` (string): an arbitrary string that will be written to the data file. You can use the :meth:`CoverageData.run_infos` method to retrieve this string @@ -153,7 +154,8 @@ many processes. See :ref:`cmd_combining` for more information. for more information. ``source`` (multi-string): a list of packages or directories, the source to -measure during execution. See :ref:`source` for details. +measure during execution. If set, ``include`` is ignored. See :ref:`source` +for details. ``timid`` (boolean, default False): use a simpler but slower trace method. This uses PyTracer instead of CTracer, and is only needed in very unusual diff --git a/doc/source.rst b/doc/source.rst index 8d831c44..640fc431 100644 --- a/doc/source.rst +++ b/doc/source.rst @@ -66,6 +66,9 @@ are interpreted relative to the current directory:: The ``source``, ``include``, and ``omit`` values all work together to determine the source that will be measured. +If both ``source`` and ``include`` are set, the ``include`` value is ignored +and a warning is printed on the standard output. + .. _source_reporting: diff --git a/tests/test_api.py b/tests/test_api.py index 56184586..8beb630d 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -579,6 +579,13 @@ class SourceOmitIncludeTest(OmitIncludeTestsMixin, CoverageTest): summary[k[:-3]] = v return summary + def test_source_include_exclusive(self): + lines = self.coverage_usepkgs(source=["pkg1"], include=["pkg2"]) + self.filenames_in(lines, "p1a p1b") + self.filenames_not_in(lines, "p2a p2b othera otherb osa osb") + out = self.stdout() + self.assertIn("--include is ignored", out) + def test_source_package_as_dir(self): # pkg1 is a directory, since we cd'd into tests/modules in setUp. lines = self.coverage_usepkgs(source=["pkg1"]) diff --git a/tests/test_config.py b/tests/test_config.py index a97a436f..a9c74aa0 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -264,6 +264,8 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest): cover_pylib = TRUE parallel = on concurrency = thread + ; this omit is overriden by the omit from [report] + omit = twenty source = myapp plugins = plugins.a_plugin @@ -283,6 +285,7 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest): omit = one, another, some_more, yet_more + include = thirty precision = 3 partial_branches = @@ -354,7 +357,9 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest): self.assertEqual(cov.get_exclude_list(), ["if 0:", r"pragma:?\s+no cover", "another_tab"]) self.assertTrue(cov.config.ignore_errors) - self.assertEqual(cov.config.omit, ["one", "another", "some_more", "yet_more"]) + self.assertEqual(cov.config.run_omit, cov.config.report_omit) + self.assertEqual(cov.config.report_omit, ["one", "another", "some_more", "yet_more"]) + self.assertEqual(cov.config.report_include, ["thirty"]) self.assertEqual(cov.config.precision, 3) self.assertEqual(cov.config.partial_list, [r"pragma:?\s+no branch"]) @@ -423,8 +428,8 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest): branch = true """) cov = coverage.Coverage() - self.assertEqual(cov.config.include, ["foo"]) - self.assertEqual(cov.config.omit, None) + self.assertEqual(cov.config.run_include, ["foo"]) + self.assertEqual(cov.config.run_omit, None) self.assertEqual(cov.config.branch, False) def test_setupcfg_only_if_not_coveragerc(self): @@ -441,7 +446,7 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest): branch = true """) cov = coverage.Coverage() - self.assertEqual(cov.config.omit, None) + self.assertEqual(cov.config.run_omit, None) self.assertEqual(cov.config.branch, False) def test_setupcfg_only_if_prefixed(self): diff --git a/tests/test_debug.py b/tests/test_debug.py index f733d723..38f31f58 100644 --- a/tests/test_debug.py +++ b/tests/test_debug.py @@ -147,8 +147,9 @@ class DebugTraceTest(CoverageTest): labels = """ attempted_config_files branch config_files cover_pylib data_file debug exclude_list extra_css html_dir html_title ignore_errors - include omit parallel partial_always_list partial_list paths + run_include run_omit parallel partial_always_list partial_list paths precision show_missing source timid xml_output + report_include report_omit """.split() for label in labels: label_pat = r"^\s*%s: " % label |