diff --git a/CHANGES.rst b/CHANGES.rst index 979d53543..958b9f5a5 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 16fb9a8a6..baddadddf 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 eced16163..4baea3319 100644 --- a/coverage/sqldata.py +++ b/coverage/sqldata.py @@ -289,6 +289,7 @@ def _read_db(self) -> None: 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 @@ def _read_db(self) -> None: ) ) from exc else: - assert row is not None schema_version = row[0] if schema_version != SCHEMA_VERSION: raise DataError(