Skip to content

coverage lcov emits duplicate function names (e.g. property getter/setter), which lcov >= 2.4 rejects as inconsistent #2335

Closed

Description

@mrossinek

Describe the bug

coverage lcov writes one FN: record per function definition, named by its qualified name. When the same qualified name is defined more than once in a file, the report contains several FN: records with the same name but different line ranges. The most common case is a property with a setter (both the getter and the setter are named C.x), but typing.overload stubs and functions redefined in if/else branches hit it too.

lcov identifies functions by name within a source file, and recent versions (we confirmed 2.4 and 2.6) treat this as a fatal (inconsistent) error when reading the tracefile. So any workflow that post-processes a coverage lcov report with lcov (for example, merging it with C/Rust coverage before uploading to Coveralls) breaks as soon as the code under test contains a property setter. We ran into this when GitHub's ubuntu-latest moved to Ubuntu 26.04, which ships lcov 2.4.

To Reproduce

repro.py:

class C:
    @property
    def x(self):
        return 1

    @x.setter
    def x(self, value):
        pass


c = C()
c.x = c.x
$ coverage run repro.py
$ coverage lcov -o out.info -q
$ cat out.info
SF:repro.py
DA:1,1
DA:2,1
DA:3,1
DA:4,1
DA:6,1
DA:7,1
DA:8,1
DA:11,1
DA:12,1
LF:9
LH:9
FN:3,4,C.x
FNDA:1,C.x
FN:7,8,C.x
FNDA:1,C.x
FNF:2
FNH:2
end_of_record
$ lcov --add-tracefile out.info --output-file merged.info
lcov: ERROR: (corrupt) unable to read trace file 'out.info': lcov: ERROR: (inconsistent) "out.info":15: duplicate function 'C.x' starts on line "repro.py":7 but previous definition started on 3 while merging out.info while loading out.info.
	(use "lcov --ignore-errors inconsistent ..." to bypass this error)
	(use "lcov --ignore-errors corrupt ..." to bypass this error)

Answer the questions below:

  1. What version of Python are you using? 3.14.8
  2. What version of coverage.py shows the problem? The output of coverage debug sys is helpful. 7.16.2

From reading coverage/lcovreport.py on master, lcov_functions() still writes FN:{first_line},{last_line},{name} for every function region with no de-duplication, so this should affect current master too.

Output of coverage debug sys
-- sys -------------------------------------------------------
               coverage_version: 7.16.2
                coverage_module: /path/to/project/.direnv/python-3.14/lib64/python3.14/site-packages/coverage/__init__.py
                           core: -none-
                        CTracer: available from /path/to/project/.direnv/python-3.14/lib64/python3.14/site-packages/coverage/tracer.cpython-314-x86_64-linux-gnu.so
           plugins.file_tracers: -none-
            plugins.configurers: -none-
      plugins.context_switchers: -none-
              configs_attempted: /path/to/project/.coveragerc
                                 /path/to/project/.coveragerc.toml
                                 /path/to/project/setup.cfg
                                 /path/to/project/tox.ini
                                 /path/to/project/pyproject.toml
                   configs_read: /path/to/project/tox.ini
                                 /path/to/project/pyproject.toml
                    config_file: /path/to/project/pyproject.toml
                config_contents: b'[build-system]\n# This is duplicated as `dependency-groups.build` for convenience.\nrequires = [\n    "setuptools>=77.0.1",\n    "setuptools-rust",\n    "qiskit~=2.5.0",\n]\nbuild-backend = "setuptools.build_meta"\n\n[project]\nname = "qiskit-fermions"\ndynamic = ["version"]\nreadme = "README.md"\ndescription = "A toolkit for working with fermionic systems"\nlicense = "Apache-2.0"\nlicense-files = ["LICENSE.txt"]\nclassifiers = [\n    "Development Status :: 4 - Beta",\n    "Intended Audience :: Developers",\n    "Intended Audience :: Science/Research",\n    "Natural Language :: English",\n    "Operating System :: MacOS",\n    "Operating System :: Microsoft :: Windows",\n    "Operating System :: POSIX :: Linux",\n    "Programming Language :: Python :: 3.10",\n    "Programming Language :: Python :: 3.11",\n    "Programming Language :: Python :: 3.12",\n    "Programming Language :: Python :: 3.13",\n    "Programming Language :: Python :: 3.14",\n    "Programming Language :: Rust",\n    "Topic :: Scientific/Engineering :: Physics",\n    "Typing :: Typed",\n]\n\nrequires-python = ">=3.10"\n\ndependencies = [\n    # Pinned to a single minor: `crates/qiskit-pyo3-ffi` is a pre-generated FFI snapshot tied to\n    # this Qiskit release, and its stability across Qiskit minors is not yet guaranteed. Widen\n    # this once a new minor has been verified against the vendored FFI.\n    "qiskit~=2.5.0",\n    "scipy>=1.10",\n    "stevedore>=3.0.0",\n    "typing-extensions",\n]\n\n# Rendered as the sidebar links on the PyPI project page.\n[project.urls]\nHomepage = "https://github.com/Qiskit/qiskit-fermions"\nDocumentation = "https://quantum.cloud.ibm.com/docs/addons/qiskit-fermions"\nRepository = "https://github.com/Qiskit/qiskit-fermions"\nIssues = "https://github.com/Qiskit/qiskit-fermions/issues"\n\n[project.optional-dependencies]\nall = [\n    "qiskit-fermions[ffsim,pyomo]",\n]\nffsim = [\n    # ffsim (and its unconditional PySCF dependency) does not support Windows, so restrict it to\n    # non-Windows platforms. The ansatz gates of the circuit library take an ffsim operator as their\n    # input, so they require this extra; everything else in the package works without it.\n    "ffsim; sys_platform != \'win32\'",\n]\npyomo = [\n    # Pyomo is a modeling layer, not a solver: choosing one is deliberately left to the user (see\n    # `RelabelModes.solver`), so this extra intentionally does not pull one in. The `highspy` entry\n    # in the `test` dependency group is only our dev-suite choice and must not be prescribed here.\n    "pyomo",\n]\n\n[dependency-groups]\nbuild = [\n    "setuptools>=77.0.1",\n    "setuptools-rust",\n    "qiskit~=2.5.0",\n]\nstyle = [\n    "ruff==0.16.9",\n    "typos>=1.20.0",\n]\nlint = [\n    {include-group = "style"},\n    "mypy==2.3.1",\n    "reno>=4.1",\n    "toml>=0.10.2",\n]\n# Three tiers, each adding one layer, so that no requirement is declared twice. Deliberately kept\n# separate: the wheel smoke test installs `basetest` alone, and `test` must *not* inherit the optional\n# dependencies that `guidetest` adds. See the "Optional dependencies" section of tests/README.md for\n# why that boundary matters.\nbasetest = [\n    "pytest>=8.0",\n    "pytest-subtests>=0.15.0",\n]\ndoctest = [\n    {include-group = "basetest"},\n    "sybil>=9.3.0",\n    "rustworkx[mpl]",\n    "pylatexenc",\n]\nguidetest = [\n    {include-group = "doctest"},\n    # Neither supports Windows, so both are gated and the doctests needing them skip there.\n    "ffsim; sys_platform != \'win32\'",\n    "qiskit-addon-sqd; sys_platform != \'win32\'",\n]\ntest = [\n    {include-group = "doctest"},\n    "highspy>=1.7.1",\n]\ncoverage = [\n    {include-group = "test"},\n    "pytest-cov>=7.1.0",\n]\ndocs = [\n    {include-group = "guidetest"},\n    "qiskit-sphinx-theme~=2.1.0",\n    "sphinx-design",\n    "sphinx-autodoc-typehints",\n    "sphinx-copybutton",\n    "sphinx_reredirects",\n    "sphinxcontrib-katex",\n    "nbsphinx>=0.9.4",\n    "reno>=4.1",\n    "breathe>=4.36.0",\n]\ndev = [\n    {include-group = "docs"},\n    {include-group = "lint"},\n    {include-group = "coverage"},\n    "tox>=4.28.0",\n]\n\n[project.entry-points."qiskit_fermions.transpiler.synthesis"]\n"Evolution.MapperFn" = "qiskit_fermions.transpiler.passes.synthesis:MapperFnEvolutionSynthesis"\n"FermionicMeasure.TrivialOccupation" = "qiskit_fermions.transpiler.passes.synthesis:TrivialOccupationFermionicMeasureSynthesis"\n"InitializeModes.TrivialOccupation" = "qiskit_fermions.transpiler.passes.synthesis:TrivialOccupationInitializeModesSynthesis"\n"OrbitalRotation.GivensDecomposition" = "qiskit_fermions.transpiler.passes.synthesis:GivensDecompositionOrbitalRotationSynthesis"\n"PrepareSlaterDeterminant.GivensDecompositionSlater" = "qiskit_fermions.transpiler.passes.synthesis:GivensDecompositionSlaterDeterminantSynthesis"\n\n[tool.setuptools]\ninclude-package-data = true\n\n[tool.setuptools.dynamic]\nversion = { attr = "qiskit_fermions.version.__version__" }\n\n[tool.setuptools.package-data]\n# `py.typed` marks the package as typed (PEP 561); the `_lib/**/*.pyi` stubs are the\n# pyo3-stub-gen output for the compiled extension and must ship in the wheel so the\n# native API is typed for downstream consumers (the pure-Python API is typed inline).\nqiskit_fermions = ["VERSION.txt", "py.typed", "_lib/**/*.pyi"]\n\n[tool.setuptools.packages.find]\nwhere = ["python"]\ninclude = ["qiskit_fermions", "qiskit_fermions.*"]\n\n[tool.coverage.run]\nbranch = true\nparallel = true\nomit = [\n    # `version.py` shells out to git and is exercised only during packaging, not by the test\n    # suite; exclude the whole file rather than annotating every line with `# pragma: no cover`.\n    "*/qiskit_fermions/version.py",\n]\n\n[tool.coverage.report]\nfail_under = 95\nshow_missing = true\n\n[tool.mypy]\npython_version = "3.10"\nshow_error_codes = true\nwarn_return_any = true\nwarn_unused_configs = true\nwarn_unused_ignores = true\nignore_missing_imports = true\n\n[tool.pytest.ini_options]\ntestpaths = ["./python/qiskit_fermions/", "./tests/python/"]\nmarkers = [\n    # Applied automatically by `tests/python/conftest.py` to every test whose module imports an\n    # optional dependency; `make testoptional` selects it together with the hand-written `skipif`\n    # markers. Do not apply it by hand.\n    "optionaldep: test requires an optional dependency (added automatically, do not set manually)",\n]\n\n[tool.ruff]\nline-length = 100\nsrc = ["python/qiskit_fermions", "tests/python"]\ntarget-version = "py310"\n# The `_lib/**/*.pyi` stubs are verbatim `pyo3-stub-gen` output (see tests/README.md, "Type\n# stubs"); they are generated, never hand-edited, and follow the generator\'s own style rather than\n# ours, so we exclude them from both `ruff format` and `ruff check`.\nextend-exclude = ["python/qiskit_fermions/_lib"]\n\n[tool.ruff.lint]\nselect = [\n    "I",   # isort\n    "E",   # pycodestyle\n    "W",   # pycodestyle\n    "D",   # pydocstyle\n    "F",   # pyflakes\n    "RUF", # ruff\n    "UP",  # pyupgrade\n    "SIM", # flake8-simplify\n    "B",   # flake8-bugbear\n    "A",   # flake8-builtins\n]\nignore = [\n    "E501", # line too long\n]\n\n[tool.ruff.lint.extend-per-file-ignores]\n"tests/python/**.py" = [\n    "D",  # pydocstyle\n]\n"docs/**/*" = [\n    "E402", # module level import not at top of file\n    "D",    # pydocstyle\n]\n"python/qiskit_fermions/**/majorana_operator.py" = [\n    "RUF002", # ambiguous unicode character in docstring: \xce\xb3 is a Majorana-operator symbol, not a typo\n]\n\n[tool.ruff.lint.pydocstyle]\nconvention = "google"\n\n[tool.typos.default.extend-words]\narange = "arange"\nba = "ba"\niz = "iz"\nket = "ket"\nthr = "thr"\n\n[tool.typos.default.extend-identifiers]\n# numpy\'s array type; `ND` trips the "should be AND" heuristic. Spelled out verbatim in the\n# `occupation_axis_mask` stub-type override in crates/pyext (the generated `.pyi` are excluded).\nNDArray = "NDArray"\n\n[tool.typos.files]\nextend-exclude = ["crates/qiskit-pyo3-ffi"]\n\n# `pyext` is built abi3 (see `crates/pyext/Cargo.toml`\'s `pyo3` feature `abi3-py310` and\n# `setup.py`\'s `py_limited_api="cp310"`), so cibuildwheel collapses each platform down to a\n# single `cp310-abi3` wheel.\n[tool.cibuildwheel]\nmanylinux-x86_64-image = "manylinux_2_28"\nmanylinux-aarch64-image = "manylinux_2_28"\nbuild = ["cp3??-*"]\nskip = [\n    "cp315-*",  # not yet supported\n    "*-win32",\n    "*_i686",\n    "*_universal2",\n    "*-musllinux_*",\n]\n# Run straight from the source checkout: passing an explicit path (`{project}/tests/python`) on\n# the command line makes pytest ignore `[tool.pytest.ini_options].testpaths`, so it never walks\n# into `python/qiskit_fermions/` and picks up the Sybil-collected doctests there (those stay owned\n# by `test_latest_versions.yml`; here we only want the plain `tests/python` suite against the\n# installed wheel). The doctests are not *run* here (`-p no:doctest`), but `doctest` is still the\n# group to install rather than `basetest`: `tests/python/conftest.py` imports Sybil to infer the\n# `optionaldep` marker, so the collection needs the doctest machinery importable even though it\n# collects no doctests. `guidetest` stays out, since nothing here needs the optional dependencies.\n# Both the `--group` and the test path are qualified with `{project}` rather than relying on a\n# `cd`, since cibuildwheel runs the test command from its own scratch directory (not the source\n# checkout) and, on Windows, a `cd ... &&`-chained command does not reliably carry its directory\n# change through to the rest of the chain.\ntest-command = "pip install --group {project}/pyproject.toml:doctest && python -m pytest -p no:doctest -s {project}/tests/python"\nenvironment = \'RUSTUP_TOOLCHAIN="stable"\'\n\n[tool.cibuildwheel.linux]\nbefore-all = "curl --proto \'=https\' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y"\nenvironment = \'PATH="$PATH:$HOME/.cargo/bin" CARGO_NET_GIT_FETCH_WITH_CLI="true" RUSTUP_TOOLCHAIN="stable"\'\nrepair-wheel-command = "auditwheel repair -w {dest_dir} {wheel} && pipx run abi3audit --strict --report {wheel}"\n\n[tool.cibuildwheel.macos]\n# A single floor for both architectures: `rustc` raises it to 11.0 for `aarch64-apple-darwin` (the\n# oldest macOS with arm64 support) on its own, so the arm64 wheels still come out tagged\n# `macosx_11_0_arm64` while the x86_64 ones reach back to the older Intel machines that can still run\n# them.  10.12 is also `rustc`\'s own default for `x86_64-apple-darwin`.\nenvironment = "MACOSX_DEPLOYMENT_TARGET=\'10.12\' RUSTUP_TOOLCHAIN=stable"\nrepair-wheel-command = "delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel} && pipx run abi3audit --strict --report {wheel}"\n\n[tool.cibuildwheel.windows]\nrepair-wheel-command = "cp {wheel} {dest_dir}/. && pipx run abi3audit --strict --report {wheel}"\n'
                      data_file: -none-
                         python: 3.14.8 (main, Oct  1 2026, 00:00:00) [GCC 16.2.1 20260819 (Red Hat 16.2.1-2)]
                       platform: Linux-7.2.10-200.fc44.x86_64-x86_64-with-glibc2.43
                 implementation: CPython
                          build: ('main', 'Oct  1 2026 00:00:00')
                    gil_enabled: True
                     executable: /path/to/project/.direnv/python-3.14/bin/python
                      pth_files: /path/to/project/.direnv/python-3.14/lib64/python3.14/site-packages/a1_coverage.pth
                                 /path/to/project/.direnv/python-3.14/lib/python3.14/site-packages/a1_coverage.pth
                   def_encoding: utf-8
                    fs_encoding: utf-8
                            pid: 408502
                            cwd: /path/to/project
                           path: /path/to/project/.direnv/python-3.14/bin
                                 /usr/lib64/python314.zip
                                 /usr/lib64/python3.14
                                 /usr/lib64/python3.14/lib-dynload
                                 /path/to/project/.direnv/python-3.14/lib64/python3.14/site-packages
                                 /path/to/project/.direnv/python-3.14/lib/python3.14/site-packages
                    environment: HOME = /home/user
                   command_line: /path/to/project/.direnv/python-3.14/bin/coverage debug sys
                           time: 2026-10-19 11:22:44
  1. What versions of what packages do you have installed? The output of pip freeze is helpful.
The output of pip freeze
accessible-pygments==0.0.5
alabaster==1.0.0
atpublic==9.0.0
attrs==26.1.0
babel==2.18.0
beautifulsoup4==4.15.0
bleach==6.4.0
breathe==5.1.0
build==1.6.1
cachetools==7.2.3
certifi==2026.10.18
charset-normalizer==3.5.2
colorama==0.4.6
contourpy==1.4.0
coverage==7.16.2
cycler==0.12.1
defusedxml==0.7.1
dill==0.4.1
distlib==0.4.4
docutils==0.22.4
dulwich==1.2.17
fastjsonschema==2.22.2
ffsim==0.0.84
filelock==4.2.4
fonttools==4.67.0
furo==2025.12.19
h5py==3.16.0
highspy==1.15.1
idna==3.20
imagesize==2.0.1
importlib_metadata==9.0.1
importlib_resources==7.1.0
iniconfig==2.3.1
jax==0.11.2
jaxlib==0.11.2
Jinja2==3.1.6
jsonschema==4.26.0
jsonschema-specifications==2025.9.1
jupyter_client==8.10.0
jupyter_core==5.9.1
jupyterlab_pygments==0.3.0
kiwisolver==1.5.1
lcov==1.15.5a0
MarkupSafe==3.0.4
matplotlib==3.11.2
mistune==3.3.4
ml_dtypes==0.6.0
nbclient==0.11.0
nbconvert==7.17.2
nbformat==5.11.1
nbsphinx==0.9.8
numpy==2.5.4
opt_einsum==3.4.0
orjson==3.13.0
packaging==26.3
pandocfilters==1.5.1
pbr==7.1.3
pillow==13.0.0
pkg_about==2.5.1
platformdirs==4.13.5
pluggy==1.7.0
Pygments==2.21.0
pylatexenc==2.11
pyparsing==3.3.3
pyproject-api==1.12.0
pyproject_hooks==1.3.3
pyscf==2.14.0
pytest==9.1.1
pytest-cov==7.1.0
pytest-subtests==0.15.0
python-dateutil==2.9.0.post0
python-discovery==1.6.4
PyYAML==6.0.3
pyzmq==27.2.0
qiskit==2.5.2
qiskit-addon-sqd==0.14.0
qiskit-sphinx-theme==2.1.1
referencing==0.37.0
reno==4.1.0
requests==2.34.2
roman-numerals==4.1.0
rpds-py==2026.9.1
rustworkx==0.18.1
scipy==1.18.1
semantic-version==2.10.0
setuptools==84.0.0
setuptools-rust==1.13.0
six==1.17.0
snowballstemmer==3.1.1
soupsieve==3.0.3
Sphinx==9.1.0
sphinx-autodoc-typehints==3.17.2
sphinx-basic-ng==1.0.0b2
sphinx-copybutton==0.5.2
sphinx-reredirects==1.1.0
sphinx_design==0.7.0
sphinxcontrib-applehelp==2.0.0
sphinxcontrib-devhelp==2.0.0
sphinxcontrib-htmlhelp==2.1.0
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-katex==0.9.11
sphinxcontrib-qthelp==2.0.0
sphinxcontrib-serializinghtml==2.0.0
stevedore==5.9.1
sybil==10.1.0
tinycss2==1.5.1
tomli_w==1.2.0
tornado==6.5.10
tox==4.67.1
traitlets==5.16.1
typing_extensions==4.16.0
urllib3==2.8.0
virtualenv==21.14.11
webencodings==0.6.1
zipp==4.1.1
  1. What code shows the problem? Give us a specific commit of a specific repo that we can check out. If you've already worked around the problem, please provide a commit before that fix.

The problem comes from here: https://github.com/Qiskit/qiskit-fermions/blob/bfe2aa94574c2dbaa45bcbafa470170da027bfc9/Makefile#L273

  1. What commands should we run to reproduce the problem? Be specific. Include everything, even git clone, pip install, and so on. Explain like we're five!

Here are the exact steps:

  1. install lcov 2.4 or newer: e.g. by downloading the .tar.gz from https://github.com/linux-test-project/lcov/releases/tag/v2.4 and running DESTDIR=/some/safe/path make install from the unpacked archive
  2. create a new python environment (the version should not really matter)
  3. pip install coveragepy==7.16.2
  4. coverage run repro.py
  5. coverage lcov -o out.info -q
  6. lcov --add-tracefile out.info --output-file merged.info and observe the problem

Expected behavior

Every function name in an LCOV record set is unique, so that lcov accepts the report without needing --ignore-errors inconsistent.

Additional context

With --ignore-errors inconsistent, lcov downgrades the error to a warning and merges the two records into one function spanning only the first definition (FNL:0,3,4 / FNA:0,2,C.x), so the setter's lines are silently attributed to the getter. That is a workaround, but it hides the whole inconsistent category, including real data problems.

Possible fixes, depending on what you prefer:

  1. Disambiguate repeated names, for example by appending the start line (C.x@7) or a role suffix for property accessors (C.x.setter).
  2. Emit only the first definition of a repeated name. This matches what lcov ends up doing anyway, but loses the setter's own function coverage.

Activity

  1. added
    bug
    on Oct 19, 2026
  2. nedbat commented on Oct 19, 2026

    @nedbat
    Member

    Since there are cases other than setters that can cause this, appending the line number seems like the best fix. To prevent too much bookkeeping, appending to only second and subsequent names could be the simplest.

  3. nedbat commented on Oct 19, 2026

    @nedbat
    Member

    This was a good one! A really simple fix (in commit cc2ee17), but it uncovered a deeper problem that has now also been fixed.

  4. mrossinek commented on Oct 19, 2026

    @mrossinek
    Author

    Thanks a lot for the super quick turnaround! 🚀

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions