summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.rst4
-rw-r--r--coverage/control.py2
-rw-r--r--tests/test_api.py15
3 files changed, 20 insertions, 1 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 59dc53f6..cf9b1571 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -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
@@ -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
diff --git a/coverage/control.py b/coverage/control.py
index 3a0b0107..e8d4bc95 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -716,7 +716,7 @@ class Coverage(object):
# 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)
diff --git a/tests/test_api.py b/tests/test_api.py
index 287391cb..7e43a6bb 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -295,6 +295,21 @@ class ApiTest(CoverageTest):
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!"