Tox+coverage not working

I’m trying to declare the proper coverage bits in a tox.ini file. Nothing breaks, but the coverage is always zero. I was working with the example in this file and came up with tox.ini:

[tox]
envlist = py{37,38,39,310,311,312,313},report
minversion = 3.3.0
isolated_build = true

[testenv]
deps =
    check-manifest >= 0.42
    pytest
    pytest-cov
commands =
    check-manifest --ignore 'tox.ini,tests/**,.editorconfig,vscode.env,.vscode/**'
    python setup.py check -m -s
    pytest tests {posargs}
depends =
    report: py{37,38,39,310,311,312,313}

[testenv:report]
deps = coverage
skip_install = true
commands =
    coverage report
    coverage html

The few tests which exist pass (strongly suggesting some lines were executed), but the coverage report shows no coverage:

report: install_deps> python -I -m pip install coverage
report: commands[0]> coverage report
Name                       Stmts   Miss  Cover
----------------------------------------------
src/heic2png/__init__.py       1      1     0%
src/heic2png/cli.py           55     55     0%
src/heic2png/heic2png.py      28     28     0%
----------------------------------------------
TOTAL                         84     84     0%
report: commands[1]> coverage html
Wrote HTML report to htmlcov/index.html

I’m not really a tox user, so most of what is in the config file is just Greek to me. I’m just copy/pasting bits then tweaking as seems correct. Any help appreciated…

Does it work when invoked via coverage .... pytest, instead of just installing pytest-coverage and running pytest normally?

Yes, after firing up one of the tox virtual envs:

(python312) ~/src/HEIC2PNG% . .tox/py312/bin/activate
(py312) (python312) ~/src/HEIC2PNG% coverage run `which pytest` tests
========================================= test session starts ==========================================
platform darwin -- Python 3.12.3, pytest-8.3.4, pluggy-1.5.0
rootdir: /Users/skip/src/HEIC2PNG
configfile: pyproject.toml
plugins: cov-6.0.0
collected 2 items                                                                                      

tests/test_heic2png.py ..                                                                        [100%]

========================================== 2 passed in 1.21s ===========================================
(py312) (python312) ~/src/HEIC2PNG% coverage report
Name                     Stmts   Miss  Cover
--------------------------------------------
tests/__init__.py            0      0   100%
tests/test_heic2png.py      46      1    98%
--------------------------------------------
TOTAL                       46      1    98%

I tried modifying the pytest command in tox.ini:

pytest --cov=src --cov-report=html --cov-append tests {posargs}

The tests run, but each one generates this warning:

tests/test_heic2png.py ./Users/skip/src/HEIC2PNG/.tox/py313/lib/python3.13t/site-packages/coverage/control.py:892: CoverageWarning: No data was collected. (no-data-collected)
  self._warn("No data was collected.", slug="no-data-collected")

I went looking for that error message and found a thread on Stack Overflow which gave conflicting results regarding a requirement (or not) for __init__.py presence in the tests directory. This is what the repo has:

% find . -name __init__.py | egrep -v '[.]/[.]tox'
./tests/__init__.py
./src/heic2png/__init__.py

I tried removing the instance in tests, but it made no difference.

BTW, the directory structure looks like this:

~/src/HEIC2PNG
├── tox.ini
├── tests
├── src
│   ├── heic2png

There are pyproject.toml, setup.cfg and setup.py files at the top level. I haven’t looked at them. They all look pretty minimal. I’m not sure which of them tox uses (not my project, just trying to add some features to the code base). tox works (minus the lack of coverage), so I’ve not yet looked into building a package.

I’ve just previously heard of problems with pytest-coverage. Isn’t running coverage in tox pretty common? I’d have a look at CI workflows that so do.