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

オープン
#642 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
42/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
testing-qa

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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"]
主要言語
Python
スター
2.1k
フォーク
256
平均マージ
6日 10分
マージ済み PR(30日)
2

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pytest-dev/pytest-cov のほかの issue

pytest-dev/pytest-cov の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。