diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2023-01-03 18:23:56 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2023-01-03 18:23:56 -0500 |
commit | 1f34d8b095d8e7c9d3276f1fc768a5d83d9e2aff (patch) | |
tree | a02ffffd3fa071da20116422aa63d1613ff321df | |
parent | 85170bf147c93f88c9d1580de3eb53da01082f18 (diff) | |
download | python-coveragepy-git-1f34d8b095d8e7c9d3276f1fc768a5d83d9e2aff.tar.gz |
fix: race condition on data file shouldn't break combining. #1522
-rw-r--r-- | CHANGES.rst | 9 | ||||
-rw-r--r-- | coverage/data.py | 2 | ||||
-rw-r--r-- | coverage/sqldata.py | 2 |
3 files changed, 11 insertions, 2 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index 979d5354..958b9f5a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -20,7 +20,14 @@ development at the same time, such as 4.5.x and 5.0. Unreleased ---------- -Nothing yet. +- Fix: when using pytest-cov or pytest-xdist, or perhaps both, the combining + step could fail with ``assert row is not None`` using 7.0.2. This was due to + a race condition that has always been possible and is still possible. In + 7.0.1 and before, the error was silently swallowed by the combining code. + Now it will produce a message "Couldn't combine data file" and ignore the + data file as it used to do before 7.0.2. Closes `issue 1522`_. + +.. _issue 1522: https://github.com/nedbat/coveragepy/issues/1522 .. _changes_7-0-2: diff --git a/coverage/data.py b/coverage/data.py index 16fb9a8a..baddaddd 100644 --- a/coverage/data.py +++ b/coverage/data.py @@ -161,6 +161,8 @@ def combine_parallel_data( # The CoverageException has the file name in it, so just # use the message as the warning. data._warn(str(exc)) + if message: + message(f"Couldn't combine data file {rel_file_name}: {exc}") delete_this_one = False else: data.update(new_data, aliases=aliases) diff --git a/coverage/sqldata.py b/coverage/sqldata.py index eced1616..4baea331 100644 --- a/coverage/sqldata.py +++ b/coverage/sqldata.py @@ -289,6 +289,7 @@ class CoverageData(AutoReprMixin): with self._dbs[threading.get_ident()] as db: try: row = db.execute_one("select version from coverage_schema") + assert row is not None except Exception as exc: if "no such table: coverage_schema" in str(exc): self._init_db(db) @@ -299,7 +300,6 @@ class CoverageData(AutoReprMixin): ) ) from exc else: - assert row is not None schema_version = row[0] if schema_version != SCHEMA_VERSION: raise DataError( |