Visitar URL original
Notebook kernel coverage lost under pytest + nbval + pytest-cov (combine prints "Skipping duplicate data"). Since 7.13.1 · Issue #2370 · coveragepy/coveragepy · GitHub
Skip to content

Notebook kernel coverage lost under pytest + nbval + pytest-cov (combine prints "Skipping duplicate data"). Since 7.13.1 #2370

Open

Description

@briochh

Describe the bug
When the notebook starts a child Python process that measures nothing (e.g. subprocess.run([sys.executable, "-c", "pass"])), coverage recorded for the full notebook kernel is missing from the final report on coveragepy 7.13.1 and later. 7.13.0 reports it correctly.

To Reproduce
with mylib.py:

def work():
    x = 1
    y = 2
    return x + y

.coveragerc:

[run]
source = mylib
parallel = true
patch = subprocess

and mre.ipynb with two cells:

import mylib
print(mylib.work())
import subprocess, sys
subprocess.run([sys.executable, '-c', 'pass'], check=True)

pytest mre.ipynb --nbval-lax --cov=mylib --cov-config=.coveragerc --cov-report=json:cov.json

Then count the executed lines of mylib.py in cov.json. The expected value is 4.

coverage executed lines of mylib.py (expected 4)
7.13.0 4
7.13.1 0
7.17.2 0

Without cell 2, every version reports 4.

Alternatively see attached .py scripts
mre.py
mre builder with optional patches

When running with combine patched to keep=True (python mre_notebook.py -p keep_combine) I get two data files with the same hash in their names:

.coverage.<host>.pid<P>.<rand>.<host>.pid<C>.<rand>.HNQIp837rWOh    0 executed lines   (the child process)
.coverage.<host>.pid<P>.<rand>.HNQIp837rWOh                         4 executed lines   (the notebook's measurements)

With the optional longer script mre_notebook.py --debug-combine
(it also needs plugins/keep_combine.py), coverage's own debug output (COVERAGE_DEBUG=combine) and a re-run of
coverage combine --debug=combine on a copy of the kept files show:

Combined data file <dir>/.coverage.<host>.pid<P>.<rand>.<host>.pid<C>.<rand>.HNQIp837rWOh
Skipping duplicate data <dir>/.coverage.<host>.pid<P>.<rand>.HNQIp837rWOh
Combined 1 file, skipped 1

Versions:
coverage 7.13.0 (passing), 7.13.1 and 7.17.2 (failing); CPython 3.13; MRE run on macOS (an original, larger notebook run also failed on Linux CI); nbval 0.11.0; pytest-cov 7.1.0; pytest 9.2.0.

Activity

  1. added a commit that references this issue on Nov 11, 2026
    b2d7984
  2. nedbat commented on Nov 13, 2026

    @nedbat
    Member

    Thanks for this report, but it would be much easier for me if you could provide direct steps to reproduce. I know you've given me the .zip file, but the directions say "alternatively" and "you also need", which complicate the directions in unclear ways. You described mre.ipynb, but could have attached it instead. I guess I need to install "nbval"? A requirements.txt would make my job easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions