pythonpython-3.xpytesttoxcoverage.py

no-data-collected when running tests with tox but not when running tests with pytest


I'm using tox to run unit tests with pytest. When I run the tests with tox, it runs the tests and shows the tree of my src directory but prints CoverageWarning: No data was collected. (no-data-collected). When I run with pytest I get the exact same output except without the error and the coverage numbers get printed as expected. My tox.ini looks like this:

[tox]
envlist = py39

[testenv]
deps = 
    pytest
    pytest-cov
    -rrequirements.txt
    -rrequirements.test

commands = pytest {posargs}

[pytest]
addopts =
    -v
    --cov=src
    tests/

I've tried other solutions mentioned on SO, such as


Solution

  • I changed my tox.ini to

    [tox]
    envlist = py39
    
    [testenv]
    deps = 
        pytest
        pytest-cov
        -rrequirements.txt
        -rrequirements.test
    
    commands = pytest --cov=src {posargs:tests}
    
    [pytest]
    pythonpath = ./src
    

    which solved the issue. I guess pytest needed the path to be explicitly passed in.