Skip to content

Commit

Permalink
fix: don't create a data file when just trying to read one. #1328
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed May 22, 2022
1 parent d849b25 commit e6df5b3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Expand Up @@ -41,13 +41,18 @@ Version 6.4 — 2022-05-22
- A new debug option ``debug=sqldata`` adds more detail to ``debug=sql``,
logging all the data being written to the database.

- Previously, running ``coverage report`` (or any of the reporting commands) in
an empty directory would create a .coverage data file. Now they do not,
fixing `issue 1328`_.

- On Python 3.11, the ``[toml]`` extra no longer installs tomli, instead using
tomllib from the standard library. Thanks `Shantanu <pull 1359_>`_.

- In-memory CoverageData objects now properly update(), closing `issue 1323`_.

.. _issue 1310: https://github.com/nedbat/coveragepy/issues/1310
.. _issue 1323: https://github.com/nedbat/coveragepy/issues/1323
.. _issue 1328: https://github.com/nedbat/coveragepy/issues/1328
.. _issue 1351: https://github.com/nedbat/coveragepy/issues/1351
.. _pull 1354: https://github.com/nedbat/coveragepy/pull/1354
.. _pull 1359: https://github.com/nedbat/coveragepy/pull/1359
Expand Down
5 changes: 3 additions & 2 deletions coverage/sqldata.py
Expand Up @@ -783,8 +783,9 @@ def erase(self, parallel=False):

def read(self):
"""Start using an existing data file."""
with self._connect(): # TODO: doesn't look right
self._have_used = True
if os.path.exists(self._filename):
with self._connect():
self._have_used = True

def write(self):
"""Ensure the data is written to the data file."""
Expand Down
7 changes: 7 additions & 0 deletions tests/test_data.py
Expand Up @@ -118,6 +118,13 @@ class CoverageDataTest(CoverageTest):
def test_empty_data_is_false(self):
covdata = DebugCoverageData()
assert not covdata
self.assert_doesnt_exist(".coverage")

def test_empty_data_is_false_when_read(self):
covdata = DebugCoverageData()
covdata.read()
assert not covdata
self.assert_doesnt_exist(".coverage")

def test_line_data_is_true(self):
covdata = DebugCoverageData()
Expand Down
1 change: 1 addition & 0 deletions tests/test_summary.py
Expand Up @@ -450,6 +450,7 @@ def test_report_skip_covered_no_data(self):
cov.load()
with pytest.raises(NoDataError, match="No data to report."):
self.get_report(cov, skip_covered=True)
self.assert_doesnt_exist(".coverage")

def test_report_skip_empty(self):
self.make_file("main.py", """
Expand Down
1 change: 1 addition & 0 deletions tests/test_xml.py
Expand Up @@ -139,6 +139,7 @@ def test_no_data(self):
with pytest.raises(NoDataError, match="No data to report."):
self.run_xml_report()
self.assert_doesnt_exist("coverage.xml")
self.assert_doesnt_exist(".coverage")

def test_no_source(self):
# Written while investigating a bug, might as well keep it.
Expand Down

0 comments on commit e6df5b3

Please sign in to comment.