diff options
-rw-r--r-- | coverage/cmdline.py | 3 | ||||
-rw-r--r-- | coverage/control.py | 4 | ||||
-rw-r--r-- | coverage/html.py | 12 | ||||
-rw-r--r-- | tests/test_cmdline.py | 2 | ||||
-rw-r--r-- | tests/test_html.py | 18 |
5 files changed, 33 insertions, 6 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py index 8942024..0b12177 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -320,6 +320,7 @@ CMDS = { Opts.include, Opts.omit, Opts.title, + Opts.skip_covered, ] + GLOBAL_ARGS, usage="[options] [modules]", description=( @@ -510,7 +511,7 @@ class CoverageScript(object): elif options.action == "html": total = self.coverage.html_report( directory=options.directory, title=options.title, - **report_args) + skip_covered=options.skip_covered, **report_args) elif options.action == "xml": outfile = options.outfile total = self.coverage.xml_report(outfile=outfile, **report_args) diff --git a/coverage/control.py b/coverage/control.py index eb0fbc4..1b7edc4 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -996,7 +996,8 @@ class Coverage(object): reporter.report(morfs, directory=directory) def html_report(self, morfs=None, directory=None, ignore_errors=None, - omit=None, include=None, extra_css=None, title=None): + omit=None, include=None, extra_css=None, title=None, + skip_covered=None): """Generate an HTML report. The HTML is written to `directory`. The file "index.html" is the @@ -1018,6 +1019,7 @@ class Coverage(object): self.config.from_args( ignore_errors=ignore_errors, omit=omit, include=include, html_dir=directory, extra_css=extra_css, html_title=title, + skip_covered=skip_covered, ) reporter = HtmlReporter(self, self.config) return reporter.report(morfs) diff --git a/coverage/html.py b/coverage/html.py index 14771dd..22783ef 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -171,6 +171,15 @@ class HtmlReporter(Reporter): def html_file(self, fr, analysis): """Generate an HTML file for one source file.""" + # Get the numbers for this file. + nums = analysis.numbers + if self.config.skip_covered: + # Don't report on 100% files. + no_missing_lines = (nums.n_missing == 0) + no_missing_branches = (nums.n_partial_branches == 0) + if no_missing_lines and no_missing_branches: + return + source = fr.source() # Find out if the file on disk is already correct. @@ -184,9 +193,6 @@ class HtmlReporter(Reporter): self.status.set_file_hash(rootname, this_hash) - # Get the numbers for this file. - nums = analysis.numbers - if self.has_arcs: missing_branch_arcs = analysis.missing_branch_arcs() arcs_executed = analysis.arcs_executed() diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index 3b982eb..116ad7d 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -39,7 +39,7 @@ class BaseCmdLineTest(CoverageTest): ) defaults.html_report( directory=None, ignore_errors=None, include=None, omit=None, morfs=[], - title=None, + skip_covered=None, title=None ) defaults.report( ignore_errors=None, include=None, omit=None, morfs=[], diff --git a/tests/test_html.py b/tests/test_html.py index b1f813e..b981362 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -447,6 +447,24 @@ class HtmlTest(HtmlTestHelpers, CoverageTest): self.run_coverage() self.assert_exists("htmlcov/status.dat") + def test_report_skip_covered_no_branches(self): + self.make_file("main.py", """ + import not_covered + + def normal(): + print("z") + normal() + """) + self.make_file("not_covered.py", """ + def not_covered(): + print("n") + """) + self.run_command("coverage run main.py") + self.run_command("coverage html --skip-covered") + self.assert_exists("htmlcov/index.html") + self.assert_doesnt_exist("htmlcov/main_py.html") + self.assert_exists("htmlcov/not_covered_py.html") + class HtmlStaticFileTest(CoverageTest): """Tests of the static file copying for the HTML report.""" |