Error combining coverage when running with pytest-xdist and a custom coverage plugin

Abierto
#642 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
42/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python
Área
testing-qa

Línea de trabajo

Start in pytest_cov/engine.py, especially the finish path where Coverage.combine is called, and reproduce the issue with the provided pytest command, xdist workers, and custom coverage plugin configuration. Confirm the fix prevents the empty master-process coverage file from being created so combining worker data succeeds without the conflicting file tracer error.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Summary

I am working on a custom coverage plugin that returns custom file tracers for Python files. When I use this coverage plugin together with pytest-xdist, it fails when combining the coverage data from the xdist workers (see traceback below).

To debug this, I added keep=True to the calls to Coverage.combine in pytest_cov/engine.py.

In an example with three xdist workers:

  • Four .coverage.* files are created: one from each worker proceses, and one from the master process.
  • All four coverage files contain the same set of files in the "files" table.
  • The coverage file generated from the master process has an empty "arc" table, and no entry in the "tracer" table.

When combining the coverage files, coverage checks if the "tracer" entries of all coverage files match. If a file is listed in the "files" table, but does not have an entry in the "tracer" table, it uses "" as the default tracer. This conflicts with the "tracer" info from the other data files, which causes coverage to error out.

To resolve this issue, pytest-cov could not create that extra, empty coverage data file from the master process.

Traceback

Traceback (most recent call last):
  File "<venv_path>/lib/python3.10/site-packages/_pytest/main.py", line 271, in wrap_session
    session.exitstatus = doit(config, session) or 0
  File "<venv_path>/lib/python3.10/site-packages/_pytest/main.py", line 325, in _main
    config.hook.pytest_runtestloop(session=session)
  File "<venv_path>/lib/python3.10/site-packages/pluggy/_hooks.py", line 501, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "<venv_path>/lib/python3.10/site-packages/pluggy/_manager.py", line 119, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "<venv_path>/lib/python3.10/site-packages/pluggy/_callers.py", line 155, in _multicall
    teardown[0].send(outcome)
  File "<venv_path>/lib/python3.10/site-packages/pytest_cov/plugin.py", line 339, in pytest_runtestloop
    self.cov_controller.finish()
  File "<venv_path>/lib/python3.10/site-packages/pytest_cov/engine.py", line 46, in ensure_topdir_wrapper
    return meth(self, *args, **kwargs)
  File "<venv_path>/lib/python3.10/site-packages/pytest_cov/engine.py", line 355, in finish
    self.cov.combine()
  File "<venv_path>/lib/python3.10/site-packages/coverage/control.py", line 836, in combine
    combine_parallel_data(
  File "<venv_path>/lib/python3.10/site-packages/coverage/data.py", line 179, in combine_parallel_data
    data.update(new_data, aliases=aliases)
  File "<venv_path>/lib/python3.10/site-packages/coverage/sqldata.py", line 760, in update
    raise DataError(
coverage.exceptions.DataError: Conflicting file tracer name for '<project_path>/tests/test_example.py': '' vs 'example_plugin.ExampleCoveragePlugin'

Versions

Python 3.10.11 on Windows

coverage                         7.4.4
pytest                           7.4.3
pytest-cov                       5.0.0
pytest-xdist                     3.5.0

The same also fails on Linux with the same package versions.

Config

pytest is run via python -m pytest --cov --cov-config=pyproject.toml -v --numprocesses=3 --maxschedchunk=1.

coverage is configured as follows:

[tool.coverage.run]
branch = true
plugins = ["example_plugin"]
concurrency = ["thread", "multiprocessing"]
Lenguaje dominante
Python
Estrellas
2.1k
Forks
253
Merge medio
6 d 10 min
PR fusionados (30 d)
2

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de pytest-dev/pytest-cov

Todos los issues de pytest-dev/pytest-cov

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.