From ba7bed0e890837eac503c9df5c1456c4369f177e Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Thu, 8 Nov 2012 23:06:36 -0500 Subject: A failure during XML reporting would leave an empty XML file behind. #210 --- coverage/control.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'coverage/control.py') 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.""" -- cgit v1.2.1