Skip to content

Commit aefe08b

Browse files
committed
Ensure file touching happens if nothing was measured. #884
1 parent acf063c commit aefe08b

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ Unreleased
3535
unwanted warnings ("Already imported a file that will be measured") and a
3636
reduction in coverage totals (`issue 909`_). This is now fixed.
3737

38+
- If no data was collected, an exception about "No data to report" could happen
39+
instead of a 0% report being created (`issue 884`_). This is now fixed.
40+
3841
- The handling of source files with non-encodable file names has changed.
3942
Previously, if a file name could not be encoded as UTF-8, an error occurred,
4043
as described in `issue 891`_. Now, those files will not be measured, since
@@ -46,6 +49,7 @@ Unreleased
4649
- ``coverage run --debug=sys`` would fail with an AttributeError. This is now
4750
fixed (`issue 907`_).
4851

52+
.. _issue 884: https://github.com/nedbat/coveragepy/issues/884
4953
.. _issue 890: https://github.com/nedbat/coveragepy/issues/890
5054
.. _issue 891: https://github.com/nedbat/coveragepy/issues/891
5155
.. _issue 901: https://github.com/nedbat/coveragepy/issues/901

coverage/control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ def _post_save_work(self):
716716

717717
# Touch all the files that could have executed, so that we can
718718
# mark completely unexecuted files as 0% covered.
719-
if self._data:
719+
if self._data is not None:
720720
for file_path, plugin_name in self._inorout.find_possibly_unexecuted_files():
721721
file_path = self._file_mapper(file_path)
722722
self._data.touch_file(file_path, plugin_name)

tests/test_api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,21 @@ def test_empty_reporting(self):
295295
with self.assertRaisesRegex(CoverageException, "No data to report."):
296296
cov.report()
297297

298+
def test_completely_zero_reporting(self):
299+
# https://github.com/nedbat/coveragepy/issues/884
300+
# If nothing was measured, the file-touching didn't happen properly.
301+
self.make_file("foo/bar.py", "print('Never run')")
302+
self.make_file("test.py", "assert True")
303+
cov = coverage.Coverage(source=["foo"])
304+
self.start_import_stop(cov, "test")
305+
cov.report()
306+
# Name Stmts Miss Cover
307+
# --------------------------------
308+
# foo/bar.py 1 1 0%
309+
310+
last = self.last_line_squeezed(self.stdout()).replace("\\", "/")
311+
self.assertEqual("foo/bar.py 1 1 0%", last)
312+
298313
def test_cov4_data_file(self):
299314
cov4_data = (
300315
"!coverage.py: This is a private format, don't read it directly!"

0 commit comments

Comments
 (0)