Skip to content

Commit 4ef91bd

Browse files
authored
feat: HTML report now says where the report is. #1195 (#1207)
1 parent 602e210 commit 4ef91bd

File tree

7 files changed

+28
-6
lines changed

7 files changed

+28
-6
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ want to know what's different in 5.0 since 4.5.x, see :ref:`whatsnew5x`.
2424
Unreleased
2525
----------
2626

27+
- The ``coverage html`` command now prints a message indicating where the HTML
28+
report was written. Fixes `issue 1195`_.
29+
2730
- Unrecognized options in the configuration file are no longer errors. They are
2831
now warnings, to ease the use of coverage across versions. Fixes `issue
2932
1035`_.
@@ -32,6 +35,7 @@ Unreleased
3235
unsupported type." (`issue 1010`_).
3336

3437
.. _issue 1035: https://github.com/nedbat/coveragepy/issues/1035
38+
.. _issue 1195: https://github.com/nedbat/coveragepy/issues/1195
3539

3640

3741
.. _changes_60b1:

coverage/cmdline.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ def command_line(self, argv):
574574
concurrency=options.concurrency,
575575
check_preimported=True,
576576
context=options.context,
577+
messages=True,
577578
)
578579

579580
if options.action == "debug":

coverage/control.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def __init__(
103103
auto_data=False, timid=None, branch=None, config_file=True,
104104
source=None, source_pkgs=None, omit=None, include=None, debug=None,
105105
concurrency=None, check_preimported=False, context=None,
106+
messages=False,
106107
): # pylint: disable=too-many-arguments
107108
"""
108109
Many of these arguments duplicate and override values that can be
@@ -173,6 +174,9 @@ def __init__(
173174
`context` is a string to use as the :ref:`static context
174175
<static_contexts>` label for collected data.
175176
177+
If `messages` is true, some messages will be printed to stdout
178+
indicating what is happening.
179+
176180
.. versionadded:: 4.0
177181
The `concurrency` parameter.
178182
@@ -185,6 +189,9 @@ def __init__(
185189
.. versionadded:: 5.3
186190
The `source_pkgs` parameter.
187191
192+
.. versionadded:: 6.0
193+
The `messages` parameter.
194+
188195
"""
189196
# data_file=None means no disk file at all. data_file missing means
190197
# use the value from the config file.
@@ -205,6 +212,7 @@ def __init__(
205212
self._warn_unimported_source = True
206213
self._warn_preimported_source = check_preimported
207214
self._no_warn_slugs = None
215+
self._messages = messages
208216

209217
# A record of all the warnings that have been issued.
210218
self._warnings = []
@@ -372,6 +380,11 @@ def _warn(self, msg, slug=None, once=False):
372380
if once:
373381
self._no_warn_slugs.append(slug)
374382

383+
def _message(self, msg):
384+
"""Write a message to the user, if configured to do so."""
385+
if self._messages:
386+
print(msg)
387+
375388
def get_option(self, option_name):
376389
"""Get an option from the configuration.
377390
@@ -969,7 +982,8 @@ def html_report(
969982
html_skip_empty=skip_empty, precision=precision,
970983
):
971984
reporter = HtmlReporter(self)
972-
return reporter.report(morfs)
985+
ret = reporter.report(morfs)
986+
return ret
973987

974988
def xml_report(
975989
self, morfs=None, outfile=None, ignore_errors=None,

coverage/html.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,9 @@ def index_file(self):
363363
'totals': self.totals,
364364
})
365365

366-
write_html(os.path.join(self.directory, "index.html"), html)
366+
index_file = os.path.join(self.directory, "index.html")
367+
write_html(index_file, html)
368+
self.coverage._message(f"Wrote HTML report to {index_file}")
367369

368370
# Write the latest hashes for next time.
369371
self.incr.write()

tests/test_cmdline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class BaseCmdLineTest(CoverageTest):
5555
_defaults.Coverage(
5656
cover_pylib=None, data_suffix=None, timid=None, branch=None,
5757
config_file=True, source=None, include=None, omit=None, debug=None,
58-
concurrency=None, check_preimported=True, context=None,
58+
concurrency=None, check_preimported=True, context=None, messages=True,
5959
)
6060

6161
DEFAULT_KWARGS = {name: kw for name, _, kw in _defaults.mock_calls}

tests/test_plugins.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import inspect
77
import io
88
import os.path
9+
import re
910
from xml.etree import ElementTree
1011

1112
import pytest
@@ -256,7 +257,7 @@ def coverage_init(reg, options):
256257
out = self.run_command("coverage run main_file.py")
257258
assert out == "MAIN\n"
258259
out = self.run_command("coverage html")
259-
assert out == ""
260+
assert re.fullmatch(r"Wrote HTML report to htmlcov[/\\]index.html\n", out)
260261

261262

262263
@pytest.mark.skipif(env.C_TRACER, reason="This test is only about PyTracer.")

tests/test_process.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,7 @@ def test_accented_dot_py(self):
12981298

12991299
# The HTML report uses ascii-encoded HTML entities.
13001300
out = self.run_command("coverage html")
1301-
assert out == ""
1301+
assert re.fullmatch(r"Wrote HTML report to htmlcov[/\\]index.html\n", out)
13021302
self.assert_exists("htmlcov/h\xe2t_py.html")
13031303
with open("htmlcov/index.html") as indexf:
13041304
index = indexf.read()
@@ -1331,7 +1331,7 @@ def test_accented_directory(self):
13311331

13321332
# The HTML report uses ascii-encoded HTML entities.
13331333
out = self.run_command("coverage html")
1334-
assert out == ""
1334+
assert re.fullmatch(r"Wrote HTML report to htmlcov[/\\]index.html\n", out)
13351335
self.assert_exists("htmlcov/d_5786906b6f0ffeb4_accented_py.html")
13361336
with open("htmlcov/index.html") as indexf:
13371337
index = indexf.read()

0 commit comments

Comments
 (0)