From 25c7c9c0133bc21da53aa41baae0442360d727d1 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sat, 20 Jan 2018 21:24:10 -0500 Subject: Don't confuse run-include with report-include (and also omit). Fixes #621 and #622. --- CHANGES.rst | 8 ++++++++ CONTRIBUTORS.txt | 1 + coverage/config.py | 14 ++++---------- tests/test_config.py | 2 +- tests/test_summary.py | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 49 insertions(+), 11 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 51a0019d..c4ec5bf4 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -13,12 +13,20 @@ Unreleased See :ref:`api_plugin` for details. This solves the complex configuration problem described in `issue 563`_. +- The ``include`` and ``omit`` options can be specified for both the ``[run]`` + and ``[report]`` phases of execution. 4.4.2 introduced some incorrect + interations between those phases, where the options for one were confused for + the other. This is now corrected, fixing `issue 621`_ and `issue 622`_. + Thanks to Daniel Hahler for seeing more clearly than I could. + - On Windows, the HTML report could fail when source trees are deeply nested, due to attempting to create HTML filenames longer than the 250-character maximum. Now filenames will never exceed 200 characters, fixing `issue 627`_. Thanks to Alex Sandro for helping with the fix. .. _issue 563: https://bitbucket.org/ned/coveragepy/issues/563/platform-specific-configuration +.. _issue 621: https://bitbucket.org/ned/coveragepy/issues/621/include-ignored-warning-when-using +.. _issue 622: https://bitbucket.org/ned/coveragepy/issues/622/report-omit-overwrites-run-omit .. _issue 627: https://bitbucket.org/ned/coveragepy/issues/627/failure-generating-html-reports-when-the diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 6c6bcd0b..953512a6 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -34,6 +34,7 @@ Cosimo Lupo Dan Riti Dan Wandschneider Danek Duvall +Daniel Hahler Danny Allen David Christian David MacIver diff --git a/coverage/config.py b/coverage/config.py index 50027274..500c2119 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -325,11 +325,11 @@ class CoverageConfig(object): ('data_file', 'run:data_file'), ('debug', 'run:debug', 'list'), ('disable_warnings', 'run:disable_warnings', 'list'), - ('_include', 'run:include', 'list'), ('note', 'run:note'), - ('_omit', 'run:omit', 'list'), ('parallel', 'run:parallel', 'boolean'), ('plugins', 'run:plugins', 'list'), + ('run_include', 'run:include', 'list'), + ('run_omit', 'run:omit', 'list'), ('source', 'run:source', 'list'), ('timid', 'run:timid', 'boolean'), @@ -337,11 +337,11 @@ 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'), ('partial_always_list', 'report:partial_branches_always', 'regexlist'), ('partial_list', 'report:partial_branches', 'regexlist'), ('precision', 'report:precision', 'int'), + ('report_include', 'report:include', 'list'), + ('report_omit', 'report:omit', 'list'), ('show_missing', 'report:show_missing', 'boolean'), ('skip_covered', 'report:skip_covered', 'boolean'), ('sort', 'report:sort'), @@ -469,12 +469,6 @@ 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/tests/test_config.py b/tests/test_config.py index a9c74aa0..0b4d40b6 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -357,7 +357,7 @@ 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.run_omit, cov.config.report_omit) + self.assertEqual(cov.config.run_omit, ["twenty"]) 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) diff --git a/tests/test_summary.py b/tests/test_summary.py index e5f470f0..36913364 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -122,6 +122,41 @@ class SummaryTest(UsingModulesMixin, CoverageTest): self.assertIn("mycode.py ", report) self.assertEqual(self.last_line_squeezed(report), "mycode.py 4 0 100%") + def test_run_source_vs_report_include(self): + # https://bitbucket.org/ned/coveragepy/issues/621/include-ignored-warning-when-using + self.make_file(".coveragerc", """\ + [run] + source = . + + [report] + include = mod/*,tests/* + """) + # It should be OK to use that configuration. + cov = coverage.Coverage() + with self.assert_warnings(cov, []): + cov.start() + cov.stop() # pragma: nested + + def test_run_omit_vs_report_omit(self): + # https://bitbucket.org/ned/coveragepy/issues/622/report-omit-overwrites-run-omit + # report:omit shouldn't clobber run:omit. + self.make_mycode() + self.make_file(".coveragerc", """\ + [run] + omit = */covmodzip1.py + + [report] + omit = */covmod1.py + """) + self.run_command("coverage run mycode.py") + + # Read the data written, to see that the right files have been omitted from running. + covdata = CoverageData() + covdata.read_file(".coverage") + files = [os.path.basename(p) for p in covdata.measured_files()] + self.assertIn("covmod1.py", files) + self.assertNotIn("covmodzip1.py", files) + def test_report_branches(self): self.make_file("mybranch.py", """\ def branch(x): -- cgit v1.2.1