Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race condition when running pytest-cov in parallel #673

Open
madig opened this issue Jan 22, 2025 · 0 comments
Open

Race condition when running pytest-cov in parallel #673

madig opened this issue Jan 22, 2025 · 0 comments

Comments

@madig
Copy link

madig commented Jan 22, 2025

Summary

Setting up a tox.ini to run pytest-cov in parallel for different Pythons like described in https://pytest-cov.readthedocs.io/en/latest/tox.html leads to crashes sometimes.

Expected vs actual result

There should be no crash.

However, see this failed Windows job: https://github.com/daltonmaag/statmake/actions/runs/12891149682/job/35942412517#step:5:69.

Here's the output from Ubuntu 24.04 on WSL, on the occasion that it crashes:

❯ tox -q -p
clean-cov: OK ✔ in 0.2 seconds
lint: OK ✔ in 0.37 seconds
py310-cov: FAIL ✖ in 1.61 seconds
================================================= test session starts ==================================================
platform linux -- Python 3.10.15, pytest-8.3.4, pluggy-1.5.0
cachedir: .tox/py310-cov/.pytest_cache
rootdir: /home/user/statmake
configfile: pyproject.toml
plugins: cov-6.0.0
collected 31 items

tests/test_cli.py .....                                                                                          [ 16%]
tests/test_make_stat.py .........................                                                                [ 96%]
tests/test_serialize.py .
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/user/statmake/.tox/py310-cov/lib/python3.10/site-packages/coverage/sqlitedb.py", line 115, in _execute
INTERNALERROR>     return self.con.execute(sql, parameters)    # type: ignore[arg-type]
INTERNALERROR> sqlite3.OperationalError: no such table: file
INTERNALERROR>
INTERNALERROR> During handling of the above exception, another exception occurred:
INTERNALERROR>
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/user/statmake/.tox/py310-cov/lib/python3.10/site-packages/coverage/sqlitedb.py", line 120, in _execute
INTERNALERROR>     return self.con.execute(sql, parameters)    # type: ignore[arg-type]
INTERNALERROR> sqlite3.OperationalError: no such table: file
INTERNALERROR>
INTERNALERROR> The above exception was the direct cause of the following exception:
INTERNALERROR>
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/user/statmake/.tox/py310-cov/lib/python3.10/site-packages/_pytest/main.py", line 283, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/home/user/statmake/.tox/py310-cov/lib/python3.10/site-packages/_pytest/main.py", line 337, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/home/user/statmake/.tox/py310-cov/lib/python3.10/site-packages/pluggy/_hooks.py", line 513, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR>   File "/home/user/statmake/.tox/py310-cov/lib/python3.10/site-packages/pluggy/_manager.py", line 120, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/home/user/statmake/.tox/py310-cov/lib/python3.10/site-packages/pluggy/_callers.py", line 156, in _multicall
INTERNALERROR>     teardown[0].send(outcome)
INTERNALERROR>   File "/home/user/statmake/.tox/py310-cov/lib/python3.10/site-packages/pytest_cov/plugin.py", line 329, in pytest_runtestloop
INTERNALERROR>     self.cov_controller.finish()
INTERNALERROR>   File "/home/user/statmake/.tox/py310-cov/lib/python3.10/site-packages/pytest_cov/engine.py", line 54, in ensure_topdir_wrapper
INTERNALERROR>     return meth(self, *args, **kwargs)
INTERNALERROR>   File "/home/user/statmake/.tox/py310-cov/lib/python3.10/site-packages/pytest_cov/engine.py", line 279, in finish
INTERNALERROR>     self.cov.combine()
INTERNALERROR>   File "/home/user/statmake/.tox/py310-cov/lib/python3.10/site-packages/coverage/control.py", line 841, in combine
INTERNALERROR>     combine_parallel_data(
INTERNALERROR>   File "/home/user/statmake/.tox/py310-cov/lib/python3.10/site-packages/coverage/data.py", line 186, in combine_parallel_data
INTERNALERROR>     data.update(new_data, map_path=map_path)
INTERNALERROR>   File "/home/user/statmake/.tox/py310-cov/lib/python3.10/site-packages/coverage/sqldata.py", line 679, in update
INTERNALERROR>     with con.execute("select path from file") as cur:
INTERNALERROR>   File "/home/user/.local/share/uv/python/cpython-3.10.15-linux-x86_64-gnu/lib/python3.10/contextlib.py", line 135, in __enter__
INTERNALERROR>     return next(self.gen)
INTERNALERROR>   File "/home/user/statmake/.tox/py310-cov/lib/python3.10/site-packages/coverage/sqlitedb.py", line 150, in execute
INTERNALERROR>     cur = self._execute(sql, parameters)
INTERNALERROR>   File "/home/user/statmake/.tox/py310-cov/lib/python3.10/site-packages/coverage/sqlitedb.py", line 138, in _execute
INTERNALERROR>     raise DataError(f"Couldn't use data file {self.filename!r}: {msg}") from exc
INTERNALERROR> coverage.exceptions.DataError: Couldn't use data file '/home/user/statmake/.coverage.DM1257.117674.XLffsVlx.c': no such table: file

================================================== 31 passed in 1.08s ==================================================
py310-cov: exit 3 (1.55 seconds) /home/user/statmake> pytest --cov --cov-append --cov-report=term-missing pid=117701
py38-cov: OK ✔ in 1.62 seconds
py39-cov: OK ✔ in 1.64 seconds
py311-cov: OK ✔ in 1.7 seconds
py313-cov: OK ✔ in 2.07 seconds
py312-cov: OK ✔ in 2.16 seconds
pypy310-cov: OK ✔ in 6.97 seconds
pypy39-cov: OK ✔ in 7.65 seconds
pypy38-cov: OK ✔ in 8.52 seconds
  lint: OK (0.36 seconds)
  clean-cov: OK (0.20 seconds)
  py38-cov: OK (1.62 seconds)
  py39-cov: OK (1.64 seconds)
  py310-cov: FAIL code 3 (1.61 seconds)
  py311-cov: OK (1.70 seconds)
  py312-cov: OK (2.16 seconds)
  py313-cov: OK (2.07 seconds)
  pypy38-cov: OK (8.52 seconds)
  pypy39-cov: OK (7.65 seconds)
  pypy310-cov: OK (6.97 seconds)
  report-cov: OK (0.24 seconds)
  evaluation failed :( (8.82 seconds)
/home/user/statmake/.tox/py310-cov/lib/python3.10/site-packages/_pytest/main.py:337: PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
Plugin: _cov, Hook: pytest_runtestloop
DataError: Couldn't use data file '/home/user/statmake/.coverage.DM1257.117674.XLffsVlx.c': no such table: file
For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning
  config.hook.pytest_runtestloop(session=session)

Reproducer

  1. Clone https://github.com/daltonmaag/statmake
  2. Repeatedly run tox -q -p until you get a crash

Versions

Running tox with tox-uv via Python 3.13.1, both installed by uv.

Package       Version
------------- -------
cachetools    5.5.1
chardet       5.2.0
colorama      0.4.6
distlib       0.3.9
filelock      3.17.0
packaging     24.2
platformdirs  4.3.6
pluggy        1.5.0
pyproject-api 1.9.0
tox           4.24.1
tox-uv        1.20.0
uv            0.5.22
virtualenv    20.29.1

pytest-cov is pinned to v6.0.0 in the statmake's lockfile for Py >= 3.9 and to v5.0.0 below.

Config

See https://github.com/daltonmaag/statmake/blob/master/tox.ini, https://github.com/daltonmaag/statmake/blob/master/.coveragerc and https://github.com/daltonmaag/statmake/blob/master/pyproject.toml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant