summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.rst4
-rw-r--r--coverage/control.py1
-rw-r--r--tests/test_api.py9
3 files changed, 14 insertions, 0 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 68128ecd..8b8f4cf6 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -20,6 +20,9 @@ Unreleased
- You can specify the command line to run your program with the ``[run]
command_line`` configuration setting. `issue 695`_.
+- Coverage will create directories as needed for the data file if they don't
+ exist, closing `issue 721`_.
+
- Coverage commands no longer clobber the first entry in sys.path, fixing
`issue 715`_.
@@ -32,6 +35,7 @@ Unreleased
.. _issue 695: https://github.com/nedbat/coveragepy/issues/695
.. _issue 715: https://github.com/nedbat/coveragepy/issues/715
.. _issue 716: https://github.com/nedbat/coveragepy/issues/716
+.. _issue 721: https://github.com/nedbat/coveragepy/issues/721
.. _changes_50a3:
diff --git a/coverage/control.py b/coverage/control.py
index a89a9da6..2eeec85c 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -408,6 +408,7 @@ class Coverage(object):
# Create the data file. We do this at construction time so that the
# data file will be written into the directory where the process
# started rather than wherever the process eventually chdir'd to.
+ ensure_dir_for_file(self.config.data_file)
self._data = CoverageData(
basename=self.config.data_file,
suffix=suffix,
diff --git a/tests/test_api.py b/tests/test_api.py
index ab9f9cf6..2f6f7a2f 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -250,6 +250,15 @@ class ApiTest(CoverageTest):
cov.save()
self.assertFiles(["datatest4.py", ".coveragerc", "mydata.dat"])
+ def test_deep_datafile(self):
+ self.make_file("datatest5.py", "fooey = 17")
+ self.assertFiles(["datatest5.py"])
+ cov = coverage.Coverage(data_file="deep/sub/cov.data")
+ self.start_import_stop(cov, "datatest5")
+ cov.save()
+ self.assertFiles(["datatest5.py", "deep"])
+ self.assert_exists("deep/sub/cov.data")
+
def test_empty_reporting(self):
# empty summary reports raise exception, just like the xml report
cov = coverage.Coverage()