Coverage by tests¶
What is Test Coverage?¶
Coverage shows how much of our code is tested. Shows paths that are not tested.
Use and installation¶
We install from pip:
$ pip install coverage
On the command line, we first run the analysis:
coverage run --source="." --omit="*/venv/*" -m pytest
then we create a report:
coverage report product.py company.py
(venv) $ coverage report example.py
Name Stmts Miss Cover
--------------------------------
example.py 9 1 89%
Coverage by tests in PyCharm¶
However, PyCharma is usually used at work. In Pycharm it is the "Run with coverage" option running on the test file. In example 1 from the chapter "Pytest - examples" it could look like this:
The green line on the left in this case is continuous, ie there is no line of code in this file that is not covered by tests. I am now removing the tests and restarting the coverage analysis. Effect:
The former green line has turned to red. This means that the rulers with the red line have not been tested. In this case, none of the lines of this function have been tested.