I have a python project where I use:
- pipenv
- tox
- pytest
and many more.
Basically, I want to add tox to my gitlab pipelines. And almost everything seems to work, calling mypy, flake8 or black from tox works fine. But when I call tox -e py37 (so I want to run the tests) with coverage enabled, the tests are run, I can see their results, but the coverage is 0% (100% only on empty __init__ files etc.) and I get the warning: Coverage.py warning: No data was collected. (no-data-collected).
This is my pytest-relevant part of tox.ini:
[tox]
envlist = flake8,mypy,black,py37
[testenv]
extras = tests
commands=
pytest --cov -ra --tb=short {posargs}
And this is my .coveragerc:
[run]
branch = True
source =
foo
omit =
foo/__init__.py
foo/__main__.py
foo/bar/__init__.py
foo/baz/__init__.py
[report]
exclude_lines =
pragma: no cover
if __name__ == .__main__.
show_missing = True
I have a working setup.py which includes all needed packages: pytest, pytest-cov and many more for style etc. (which works). I also have __init__.py in my tests folder.
Funny thing is, if I call the same command I have in tox.ini from my command line (in pipenv): pytest --cov -ra --tb=short, I get the same results but with normal coverage (in my case it's 100%).
Is there a way to fix it? I don't want my pipelines to show wrong coverage + even if they somehow magically would actually get the right one, I still would want to see it locally.
P.S When I was trying to resolve the issue I called tox with tox --sitepackages -e py37 and I got some errors like test command found but not in testenv. And besides those errors, my coverage was fine then. But then I uninstalled tox, pytest and pytest-cov from my global pip register and now with or without --sitepackages flag I still get 0% coverage
--covexpects an argument, e.g. package name or source directory or file, e.g.pytest --cov=foo.baretc. - hoefling.coveragerctakes care of that. Plus it wouldn't work from the command line if that was the issue - dabljues