# Tox+coverage not working

**URL:** <https://discuss.python.org/t/tox-coverage-not-working/79723>\
**Category:** Python Help\
**Created:** [February 6, 2025, 6:16pm UTC](https://discuss.python.org/t/tox-coverage-not-working/79723 "2025-02-06T18:16:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![smontanaro](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/smontanaro/32/1389_2.png) [@smontanaro](https://discuss.python.org/u/smontanaro)\
**Post date:** [February 6, 2025, 6:16pm UTC](https://discuss.python.org/t/tox-coverage-not-working/79723/1 "2025-02-06T18:16:44Z")

</div>

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](https://pytest-cov.readthedocs.io/en/latest/tox.html) and came up with `tox.ini`:

```python
[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:

```python
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…

---

<div class="post-metadata">

**Author:** ![JamesParrott](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jamesparrott/32/10534_2.png) [@JamesParrott](https://discuss.python.org/u/JamesParrott)\
**Post date:** [February 6, 2025, 8:34pm UTC](https://discuss.python.org/t/tox-coverage-not-working/79723/2 "2025-02-06T20:34:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![smontanaro](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/smontanaro/32/1389_2.png) [@smontanaro](https://discuss.python.org/u/smontanaro)\
**Post date:** [February 6, 2025, 10:48pm UTC](https://discuss.python.org/t/tox-coverage-not-working/79723/3 "2025-02-06T22:48:09Z")

</div>

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

```python
(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`:

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

```

The tests run, but each one generates this warning:

```python
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](https://stackoverflow.com/questions/47287721/python-coverage-output-coverage-py-warning-no-data-was-collected-no-data-col) which gave conflicting results regarding a requirement (or not) for ` __init__.py` presence in the `tests` directory. This is what the repo has:

```python
% 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:

```python
~/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.

---

<div class="post-metadata">

**Author:** ![JamesParrott](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jamesparrott/32/10534_2.png) [@JamesParrott](https://discuss.python.org/u/JamesParrott)\
**Post date:** [February 7, 2025, 8:59am UTC](https://discuss.python.org/t/tox-coverage-not-working/79723/4 "2025-02-07T08:59:38Z")

</div>

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.
