diff options
-rw-r--r-- | AUTHORS.txt | 1 | ||||
-rw-r--r-- | CHANGES.txt | 1 | ||||
-rw-r--r-- | coverage/control.py | 7 | ||||
-rw-r--r-- | tests/test_xml.py | 7 |
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") |