James Hiew James Hiew - 1 month ago 8
Python Question

Pycharm/IntelliJ shows 0% coverage for pytest even though coverage was generated

I have a Python project and a

tests
task, set up to run
pytest
from the project's working directory.

enter image description here

Doing
Run 'tests' with coverage
from the
Run
menu successfully runs the tests, and the console results shows that coverage was measured - e.g. 53% cover for
mws.py
.

enter image description here

The automatically applied coverage (as on the right) is 0% for all files, I'm not sure why. I'm using IntelliJ 2017.2.2 EAP.

NB: there is a related five year old question here, but the top rated solution there doesn't apply. There is no error message in the results console in this case.

Answer Source

I think the problem lies in you use pytest-cov, so Pycharm cannot parse the result which is shown in text like 53% generated by pytest-cov;

So Changes option in pytest.ini to addopts = -s -v when you want to use Pycharm built in coverage tools.