Skip to content

Spotty coverage of code run through multiprocessing #1910

@sprezz-arthur

Description

@sprezz-arthur

Describe the bug
The coverage of the code run through python's multiprocessing can be taken into account or not, randomly.
There seems to be some race condition happening when SIGTERM is received, sometimes coverage has time to properly report run code, sometimes it doesn't.

To Reproduce

  1. What version of Python are you using? Python 3.12.4
  2. What version of coverage.py shows the problem? coverage_version: 7.6.9
  3. What versions of what packages do you have installed? pytest@8.3.4
  4. What code shows the problem? https://github.com/sprezz-arthur/flaky-coverage-mre
  5. What commands should we run to reproduce the problem?
    rm -rf htmlcov && rm -f .coverage && coverage run -m pytest && coverage combine && coverage html

Expected behavior
I expected the code run through multiprocessing to always be taken into account

Additional context
I'm using pyproject.toml for config with the following content:

[tool.coverage.run]
branch = true
parallel = true
sigterm = true
concurrency = [
    "multiprocessing",
]

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions