summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <nedbat@gmail.com>2014-03-01 06:30:37 -0500
committerNed Batchelder <nedbat@gmail.com>2014-03-01 06:30:37 -0500
commit507471475e468322d76e668e8f1a7eb443aab594 (patch)
treef05e4f0d01425d8bf791f1ce7a437742ce85ba9b
parentce11ef95ffa9a4d5b2422dfe1a65fabda695bcb2 (diff)
parent4e1a87c430f9776fa0d4f0a1655f052a097859cd (diff)
downloadpython-coveragepy-git-507471475e468322d76e668e8f1a7eb443aab594.tar.gz
Merged in offbyone/coverage.py (pull request #31)
Resolve #285 - precreate the XML report's output directory if it does
-rw-r--r--AUTHORS.txt1
-rw-r--r--CHANGES.txt1
-rw-r--r--coverage/control.py7
-rw-r--r--tests/test_xml.py7
4 files changed, 16 insertions, 0 deletions
diff --git a/AUTHORS.txt b/AUTHORS.txt
index 5ea7e040..cc3f6477 100644
--- a/AUTHORS.txt
+++ b/AUTHORS.txt
@@ -41,3 +41,4 @@ Sigve Tjora
Mark van der Wal
Zooko Wilcox-O'Hearn
Christoph Zwerschke
+Chris Rose
diff --git a/CHANGES.txt b/CHANGES.txt
index 8819a98f..eda8d074 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -7,6 +7,7 @@ Change history for Coverage.py
- Python versions supported are now 2.6, 2.7, 3.2, 3.3.
+.. _issue 285: https://bitbucket.org/ned/coveragepy/issue/285/xml-report-fails-if-output-file-directory
3.7.1 -- 13 December 2013
-------------------------
diff --git a/coverage/control.py b/coverage/control.py
index d5e2c6f8..38c6cb4f 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -692,6 +692,13 @@ class coverage(object):
if self.config.xml_output == '-':
outfile = sys.stdout
else:
+ # Ensure that the output directory is created; done here
+ # because this report pre-opens the output file.
+ # HTMLReport does this using the Report plumbing because
+ # its task is more complex, being multiple files.
+ output_dir = os.path.dirname(self.config.xml_output)
+ if output_dir and not os.path.isdir(output_dir):
+ os.makedirs(output_dir)
outfile = open(self.config.xml_output, "w")
file_to_close = outfile
try:
diff --git a/tests/test_xml.py b/tests/test_xml.py
index 0801bad3..37ada3cb 100644
--- a/tests/test_xml.py
+++ b/tests/test_xml.py
@@ -26,6 +26,13 @@ class XmlReportTest(CoverageTest):
self.assert_doesnt_exist("coverage.xml")
self.assert_exists("put_it_there.xml")
+ def test_config_file_directory_does_not_exist(self):
+ self.run_mycode()
+ self.run_command("coverage xml -o nonexistent/put_it_there.xml")
+ self.assert_doesnt_exist("coverage.xml")
+ self.assert_doesnt_exist("put_it_there.xml")
+ self.assert_exists("nonexistent/put_it_there.xml")
+
def test_config_affects_xml_placement(self):
self.run_mycode()
self.make_file(".coveragerc", "[xml]\noutput = xml.out\n")