I have a Python project and a tests
task, set up to run pytest
from the project's working directory.
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
.
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.
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.
I had a similar issue, but the accepted solution here didn't solve it.
I had pytest
automatically run coverage in its configuration file.
In PyCharm, I added a Run Configuration to run all my tests with pytest
.
It seemed to work, and I saw all tests running and got their results to display in PyCharm's run window.
But soon I noticed there were two problems:
Both problems disappeared when I added --no-cov
to the "Additional Arguments" passed to to pytest
(this option is in the Run Configuration).
So It seems the fix was to tell pytest
to not run coverage when running it from PyCharm. Both "Run with coverage" option and the Breakpoints in tests now work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With