How to use "coverage" to detect the code that's been executed
![]() |
| source:wallpaperswide.com |
I have recently been introduced to this wonderful tool aka coverage in Python. This tool is used to measure the effectiveness of test cases. It basically tells us how much of our code is covered by test cases. More information on coverage can be found here.
PyCharm Professional edition has built in support for this tool. If you are using PyCharm Community edition then you can run this on terminal. It is very easy to install with pip.
So if our code hierarchy looks like below.
--- parent directory
------ modules
--------- module1.py
--------- module2.py
------ tests
--------- tests.py
This is how we would run coverage to evaluate the code in modules that has been executed by test cases(make sure you are in the parent directory).
To view the report, run
This will create a directory with the name coveragereport which would contain html reports for all the .py files in modules directory. To view the report, you know what to do :).

Comments
Post a Comment