Skip to content

Commit

Permalink
Ensure file touching happens if nothing was measured. #884
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Jan 4, 2020
1 parent acf063c commit aefe08b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ Unreleased
unwanted warnings ("Already imported a file that will be measured") and a
reduction in coverage totals (`issue 909`_). This is now fixed.

- If no data was collected, an exception about "No data to report" could happen
instead of a 0% report being created (`issue 884`_). This is now fixed.

- The handling of source files with non-encodable file names has changed.
Previously, if a file name could not be encoded as UTF-8, an error occurred,
as described in `issue 891`_. Now, those files will not be measured, since
Expand All @@ -46,6 +49,7 @@ Unreleased
- ``coverage run --debug=sys`` would fail with an AttributeError. This is now
fixed (`issue 907`_).

.. _issue 884: https://github.com/nedbat/coveragepy/issues/884
.. _issue 890: https://github.com/nedbat/coveragepy/issues/890
.. _issue 891: https://github.com/nedbat/coveragepy/issues/891
.. _issue 901: https://github.com/nedbat/coveragepy/issues/901
Expand Down
2 changes: 1 addition & 1 deletion coverage/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ def _post_save_work(self):

# Touch all the files that could have executed, so that we can
# mark completely unexecuted files as 0% covered.
if self._data:
if self._data is not None:
for file_path, plugin_name in self._inorout.find_possibly_unexecuted_files():
file_path = self._file_mapper(file_path)
self._data.touch_file(file_path, plugin_name)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,21 @@ def test_empty_reporting(self):
with self.assertRaisesRegex(CoverageException, "No data to report."):
cov.report()

def test_completely_zero_reporting(self):
# https://github.com/nedbat/coveragepy/issues/884
# If nothing was measured, the file-touching didn't happen properly.
self.make_file("foo/bar.py", "print('Never run')")
self.make_file("test.py", "assert True")
cov = coverage.Coverage(source=["foo"])
self.start_import_stop(cov, "test")
cov.report()
# Name Stmts Miss Cover
# --------------------------------
# foo/bar.py 1 1 0%

last = self.last_line_squeezed(self.stdout()).replace("\\", "/")
self.assertEqual("foo/bar.py 1 1 0%", last)

def test_cov4_data_file(self):
cov4_data = (
"!coverage.py: This is a private format, don't read it directly!"
Expand Down

0 comments on commit aefe08b

Please sign in to comment.