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 | d916b3b85dc05301faf243e8903b3a22dc4cf187 (patch) | |
tree | e7dfec81d62b5b05daa00593e648e59ee973e1c3 /coverage/control.py | |
parent | c978c92c7325aa52659f65e904e50e72a4e67e99 (diff) | |
download | python-coveragepy-d916b3b85dc05301faf243e8903b3a22dc4cf187.tar.gz |
A failure during XML reporting would leave an empty XML file behind. #210
Diffstat (limited to 'coverage/control.py')
-rw-r--r-- | coverage/control.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/coverage/control.py b/coverage/control.py index 006f06b..726d3f3 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.""" |