summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2018-01-21 18:04:22 -0500
committerNed Batchelder <ned@nedbatchelder.com>2018-01-21 18:04:22 -0500
commit96269ab63bcbb0bc7d5520e1dc8226608275889d (patch)
treeb93c28cf5124705b41f26cd9da52519928e384b6
parenteaf55bf6d75675220a12b59b348362f2ecaadb9f (diff)
downloadpython-coveragepy-96269ab63bcbb0bc7d5520e1dc8226608275889d.tar.gz
Raise an error if combine can't find usable data files. #629
-rw-r--r--CHANGES.rst10
-rw-r--r--coverage/data.py5
-rw-r--r--tests/test_process.py34
3 files changed, 47 insertions, 2 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 8ccc800..d6fbd09 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -24,15 +24,21 @@ Unreleased
the other. This is now corrected, fixing `issue 621`_ and `issue 622`_.
Thanks to Daniel Hahler for seeing more clearly than I could.
+- The ``coverage combine`` command used to always overwrite the data file, even
+ when no data had been read from apparently combinable files. Now, an error
+ is raised if we thought there were files to combine, but in fact none of them
+ could be used. Fixes `issue 629`_.
+
- On Windows, the HTML report could fail when source trees are deeply nested,
due to attempting to create HTML filenames longer than the 250-character
- maximum. Now filenames will never exceed 200 characters, fixing `issue
- 627`_. Thanks to Alex Sandro for helping with the fix.
+ maximum. Now filenames will never get much larger than 200 characters,
+ fixing `issue 627`_. Thanks to Alex Sandro for helping with the fix.
.. _issue 563: https://bitbucket.org/ned/coveragepy/issues/563/platform-specific-configuration
.. _issue 621: https://bitbucket.org/ned/coveragepy/issues/621/include-ignored-warning-when-using
.. _issue 622: https://bitbucket.org/ned/coveragepy/issues/622/report-omit-overwrites-run-omit
.. _issue 627: https://bitbucket.org/ned/coveragepy/issues/627/failure-generating-html-reports-when-the
+.. _issue 629: https://bitbucket.org/ned/coveragepy/issues/629/multiple-use-of-combine-leads-to-empty
.. _issue 631: https://bitbucket.org/ned/coveragepy/issues/631/precise-coverage-percentage-value
diff --git a/coverage/data.py b/coverage/data.py
index ecfb86b..6f76a72 100644
--- a/coverage/data.py
+++ b/coverage/data.py
@@ -722,6 +722,7 @@ class CoverageDataFiles(object):
if strict and not files_to_combine:
raise CoverageException("No data to combine")
+ files_combined = 0
for f in files_to_combine:
new_data = CoverageData(debug=self.debug)
try:
@@ -733,10 +734,14 @@ class CoverageDataFiles(object):
self.warn(str(exc))
else:
data.update(new_data, aliases=aliases)
+ files_combined += 1
if self.debug and self.debug.should('dataio'):
self.debug.write("Deleting combined data file %r" % (f,))
file_be_gone(f)
+ if strict and not files_combined:
+ raise CoverageException("No usable data files")
+
def canonicalize_json_data(data):
"""Canonicalize our JSON data so it can be compared."""
diff --git a/tests/test_process.py b/tests/test_process.py
index 42a6d98..18564cb 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -144,6 +144,40 @@ class ProcessTest(CoverageTest):
data.read_file(".coverage")
self.assertEqual(data.line_counts()['b_or_c.py'], 7)
+ def test_combine_no_usable_files(self):
+ # https://bitbucket.org/ned/coveragepy/issues/629/multiple-use-of-combine-leads-to-empty
+ self.make_b_or_c_py()
+ out = self.run_command("coverage run b_or_c.py b")
+ self.assertEqual(out, 'done\n')
+ self.assert_exists(".coverage")
+ self.assertEqual(self.number_of_data_files(), 1)
+
+ # Make bogus data files.
+ self.make_file(".coverage.bad1", "This isn't a coverage data file.")
+ self.make_file(".coverage.bad2", "This isn't a coverage data file.")
+
+ # Combine the parallel coverage data files into .coverage, but nothing is readable.
+ status, out = self.run_command_status("coverage combine")
+ self.assertEqual(status, 1)
+
+ for n in "12":
+ self.assert_exists(".coverage.bad{0}".format(n))
+ warning_regex = (
+ r"Coverage.py warning: Couldn't read data from '.*\.coverage\.bad{0}': "
+ r"CoverageException: Doesn't seem to be a coverage\.py data file".format(n)
+ )
+ self.assertRegex(out, warning_regex)
+ self.assertRegex(out, r"No usable data files")
+
+ # After combining, we should have a main file and two parallel files.
+ self.assertEqual(self.number_of_data_files(), 3)
+
+ # Read the coverage file and see that b_or_c.py has 6 lines
+ # executed (we only did b, not c).
+ data = coverage.CoverageData()
+ data.read_file(".coverage")
+ self.assertEqual(data.line_counts()['b_or_c.py'], 6)
+
def test_combine_parallel_data_in_two_steps(self):
self.make_b_or_c_py()