Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a statement in coverage.py?

From http://coverage.readthedocs.io/en/coverage-4.3.4/cmd.html the coverage analysis report is done by:

$ coverage report -m
Name                      Stmts   Miss  Cover   Missing
-------------------------------------------------------
my_program.py                20      4    80%   33-35, 39
my_module.py                 15      2    86%   8, 12
my_other_module.py           56      6    89%   17-23
-------------------------------------------------------
TOTAL                        91     12    87%

But, what is a statement ("Stmts") in this tool?

like image 611
eduardosufan Avatar asked May 18 '17 16:05

eduardosufan


People also ask

What is statement coverage in Python?

The coverage.py Python module provides statement coverage for Python. It accumulates coverage data over many runs; generates coverage reports; and annotates Python source showing which statements have been covered.

What is coverage Py?

An Intro to coverage.py. Coverage.py is a 3rd party tool for Python that is used for measuring your code coverage. It was originally created by Ned Batchelder. The term “coverage” in programming circles is typically used to describe the effectiveness of your tests and how much of your code is actually covered by tests.

What is statement coverage?

Statement coverage is the weakest measure of code coverage. It can't tell you when an if statement is missing an else clause ("branch coverage"); when a condition is only tested in one direction ("condition coverage"); when a loop is always taken and never skipped ("loop coverage"); and so on.

How do you measure code coverage in Python?

Coverage.py is a tool for measuring code coverage of Python programs. It monitors your program, noting which parts of the code have been executed, then analyzes the source to identify code that could have been executed but was not.


2 Answers

I realized that statements are the number of lines of code including imports, class and function definitions (not counting the comments).

like image 90
eduardosufan Avatar answered Oct 05 '22 23:10

eduardosufan


Stmts is the number of total statements. For example, for the first line, 20 statements were executed, out of which 4 were missed, so 16 were covered:

16/20 = 0.8 (80%)

which matches the 80% cover ratio in the table.

like image 41
Liran Funaro Avatar answered Oct 05 '22 22:10

Liran Funaro