How to use Coverage.py with PyCharm Community Edition
已回答
I'm using PyCharm Community Edition 2017.3 on Windows. I have coverage.py module installed through pip. I can run my unit tests and gather coverage by running these commands in a command window.
python -m unittest discover -s tests/
coverage run -m unittest discover -s tests/
coverage report -m
coverage html
This works fine. But since I need to run the unit tests frequently this isn't very convenient. I was wondering if there is a Run configuration I can create in PyCharm which would do this for me with a single click.
请先登录再写评论。
Hi Jithin10a! Coverage support is included in Professional Edition only: https://www.jetbrains.com/pycharm/features/editions_comparison_matrix.html
There's also a way to integrate it a bit better:
1. Create a batch file for whichever OS you're using. When I set this up, I happened to be on a PC so my script looked like this:
2. Create an External Tool
3. Open up/keep settings open and go to Keymap
4. Search for your external tool name in the right pane
5. Create a shortcut for it, whichever you please.
Congrats! Now you just have to hit your keyboard shortcut and it will run coverage and also open chrome to the coverage html.