pytest-cov

Page content

pytest-cov

Coverage is a useful tool for checking how well your tests are covering all your code. pytest-cov is a plugin for pytest. It adds a very simple --cov parameter that will generate a list of all the lines that will be used when the tests runs.

pytest-cov adds all these options see here

$ pytest --cov=hippocrates --cov-report=term-missing tests/
============================================================================================================ test session starts =============================================================================================================
platform darwin -- Python 3.7.4, pytest-4.3.0, py-1.8.0, pluggy-0.12.0
benchmark: 3.2.2 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /Users/channam/code/hippocrates, inifile: tox.ini
plugins: cov-2.6.1, benchmark-3.2.2
collected 31 items

tests/questionnaires/test_models.py ...                                                                                                                                                                                                [  9%]
tests/questionnaires/base/test_base.py .....................                                                                                                                                                                           [ 77%]
tests/questionnaires/bdi/test_bdi_assessment.py .                                                                                                                                                                                      [ 80%]
tests/questionnaires/gad2/test_gad2_assessment.py ..                                                                                                                                                                                   [ 87%]
tests/questionnaires/gad7/test_gad7_assessment.py .                                                                                                                                                                                    [ 90%]
tests/questionnaires/phq2/test_phq2_assessment.py .                                                                                                                                                                                    [ 93%]
tests/questionnaires/phq9/test_phq9_assessment.py .                                                                                                                                                                                    [ 96%]
tests/questionnaires/rosenberg_self_esteem/test_rosenberg_self_esteem.py .                                                                                                                                                             [100%]

---------- coverage: platform darwin, python 3.7.4-final-0 -----------
Name                                                             Stmts   Miss  Cover   Missing
----------------------------------------------------------------------------------------------
hippocrates/__init__.py                                              1      0   100%
hippocrates/command_line.py                                         29     29     0%   4-55
hippocrates/questionnaires/__init__.py                               6      0   100%
hippocrates/questionnaires/base.py                                  94     39    59%   21-25, 36, 42-48, 57-63, 70, 76, 92, 108-113, 116-119, 123-129, 134-144
hippocrates/questionnaires/beck_depression_index/__init__.py         0      0   100%
hippocrates/questionnaires/beck_depression_index/assessment.py      16      1    94%   38
hippocrates/questionnaires/gad2/__init__.py                          0      0   100%
hippocrates/questionnaires/gad2/assessment.py                       16      1    94%   34
hippocrates/questionnaires/gad7/__init__.py                          0      0   100%
hippocrates/questionnaires/gad7/assessment.py                       16      1    94%   38
hippocrates/questionnaires/models.py                                55      0   100%
hippocrates/questionnaires/phq2/__init__.py                          1      0   100%
hippocrates/questionnaires/phq2/assessment.py                       16      1    94%   34
hippocrates/questionnaires/phq9/__init__.py                          1      0   100%
hippocrates/questionnaires/phq9/assessment.py                       16      1    94%   40
hippocrates/questionnaires/rosenberg_self_esteem/__init__.py         0      0   100%
hippocrates/questionnaires/rosenberg_self_esteem/assessment.py      16      1    94%   36
hippocrates/utils/__init__.py                                        0      0   100%
----------------------------------------------------------------------------------------------
TOTAL                                                              283     74    74%


========================================================================================================= 31 passed in 0.35 seconds ==========================================================================================================

Config Options

More options available at pytest-cov

Missing Lines

--cov-report=term-missing - Adds a list of lines that won’t be hit.