Skip to content

Commit 1f34d8b

Browse files
committed
fix: race condition on data file shouldn't break combining. #1522
1 parent 85170bf commit 1f34d8b

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

CHANGES.rst

+8-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ development at the same time, such as 4.5.x and 5.0.
2020
Unreleased
2121
----------
2222

23-
Nothing yet.
23+
- Fix: when using pytest-cov or pytest-xdist, or perhaps both, the combining
24+
step could fail with ``assert row is not None`` using 7.0.2. This was due to
25+
a race condition that has always been possible and is still possible. In
26+
7.0.1 and before, the error was silently swallowed by the combining code.
27+
Now it will produce a message "Couldn't combine data file" and ignore the
28+
data file as it used to do before 7.0.2. Closes `issue 1522`_.
29+
30+
.. _issue 1522: https://github.com/nedbat/coveragepy/issues/1522
2431

2532

2633
.. _changes_7-0-2:

coverage/data.py

+2
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ def combine_parallel_data(
161161
# The CoverageException has the file name in it, so just
162162
# use the message as the warning.
163163
data._warn(str(exc))
164+
if message:
165+
message(f"Couldn't combine data file {rel_file_name}: {exc}")
164166
delete_this_one = False
165167
else:
166168
data.update(new_data, aliases=aliases)

coverage/sqldata.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ def _read_db(self) -> None:
289289
with self._dbs[threading.get_ident()] as db:
290290
try:
291291
row = db.execute_one("select version from coverage_schema")
292+
assert row is not None
292293
except Exception as exc:
293294
if "no such table: coverage_schema" in str(exc):
294295
self._init_db(db)
@@ -299,7 +300,6 @@ def _read_db(self) -> None:
299300
)
300301
) from exc
301302
else:
302-
assert row is not None
303303
schema_version = row[0]
304304
if schema_version != SCHEMA_VERSION:
305305
raise DataError(

0 commit comments

Comments
 (0)