diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2012-11-08 23:06:36 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2012-11-08 23:06:36 -0500 |
commit | ba7bed0e890837eac503c9df5c1456c4369f177e (patch) | |
tree | 45e42d81a7f48ef9b4153fa13e777483c16dd1aa | |
parent | 48bcf7bb7f6d52ea0672fbadd3bd4b05a43960c1 (diff) | |
download | python-coveragepy-git-ba7bed0e890837eac503c9df5c1456c4369f177e.tar.gz |
A failure during XML reporting would leave an empty XML file behind. #210
-rw-r--r-- | CHANGES.txt | 4 | ||||
-rw-r--r-- | coverage/control.py | 9 | ||||
-rw-r--r-- | test/test_xml.py | 11 |
3 files changed, 22 insertions, 2 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index ad4781c6..40fb5765 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -28,6 +28,9 @@ Version 3.5.4b1 HTML report would fail with a UnicodeDecodeError. This issue (`issue 193`_) is now fixed. +- If `coverage xml` fails because there is no data to report, it used to + create a zero-length XML file. Now it doesn't, fixing `issue 210`_. + - Running coverage under a debugger is unlikely to work, but it shouldn't fail with "TypeError: 'NoneType' object is not iterable". Fixes `issue 201`_. @@ -43,6 +46,7 @@ Version 3.5.4b1 .. _issue 201: https://bitbucket.org/ned/coveragepy/issue/201/coverage-using-django-14-with-pydb-on .. _issue 205: https://bitbucket.org/ned/coveragepy/issue/205/make-pydoc-coverage-more-friendly .. _issue 206: https://bitbucket.org/ned/coveragepy/issue/206/pydoc-coveragecoverage-fails-with-an-error +.. _issue 210: https://bitbucket.org/ned/coveragepy/issue/210/if-theres-no-coverage-data-coverage-xml Version 3.5.3 --- 29 September 2012 diff --git a/coverage/control.py b/coverage/control.py index 006f06ba..726d3f37 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -602,6 +602,7 @@ class coverage(object): xml_output=outfile, ) file_to_close = None + delete_file = False if self.config.xml_output: if self.config.xml_output == '-': outfile = sys.stdout @@ -611,9 +612,17 @@ class coverage(object): try: reporter = XmlReporter(self, self.config) return reporter.report(morfs, outfile=outfile) + except CoverageException: + delete_file = True + raise finally: if file_to_close: file_to_close.close() + if delete_file: + try: + os.remove(self.config.xml_output) + except Exception: + pass def sysinfo(self): """Return a list of (key, value) pairs showing internal information.""" diff --git a/test/test_xml.py b/test/test_xml.py index ba17d430..c7205a59 100644 --- a/test/test_xml.py +++ b/test/test_xml.py @@ -8,22 +8,29 @@ from coveragetest import CoverageTest class XmlReportTest(CoverageTest): """Tests of the XML reports from coverage.py.""" - def setUp(self): - super(XmlReportTest, self).setUp() + def run_mycode(self): + """Run mycode.py, so we can report on it.""" self.make_file("mycode.py", "print('hello')\n") self.run_command("coverage run mycode.py") def test_default_file_placement(self): + self.run_mycode() self.run_command("coverage xml") self.assert_exists("coverage.xml") def test_argument_affects_xml_placement(self): + self.run_mycode() self.run_command("coverage xml -o put_it_there.xml") self.assert_doesnt_exist("coverage.xml") self.assert_exists("put_it_there.xml") def test_config_affects_xml_placement(self): + self.run_mycode() self.make_file(".coveragerc", "[xml]\noutput = xml.out\n") self.run_command("coverage xml") self.assert_doesnt_exist("coverage.xml") self.assert_exists("xml.out") + + def test_no_data(self): + self.run_command("coverage xml") + self.assert_doesnt_exist("coverage.xml") |