Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python conditional coverage for subexpression

I'm trying to find a python code coverage tool which can measure if subexpressions are covered in a statement:

For instance, I'd like to see if condition1/condition2/condtion3 is covered in following example?

if condition1 or condition2 or condition3: x = true_value
like image 397
zhutoulala Avatar asked Jan 16 '14 00:01

zhutoulala


People also ask

How do you do Statement coverage in Python?

To report on the statement coverage for a set of files, use the -r option ( --report ): $ coverage.py -r [-m] FILE1 FILE2 ... To make a copy of source code annotated with > for statements that are executed, and ! for statements that are not, use the -a option ( --annotate ): $ coverage.py -a FILE1 FILE2 ...

What is the difference between branch coverage and condition coverage?

When branches contain multiple conditions, branch coverage can be 100% without instantiating all conditions to true/false. Condition coverage measures the proportion of conditions within decision expressions that have been evaluated to both true and false.

How do you increase code coverage in Python?

Increase coverage by adding more tests The code coverage has increased to 78% on adding another test case. It can be increased further to 100% in a similar fashion.


1 Answers

The only reasonable answer to this is: There is no current out-of-the-box implementation.

The closest thing which has branch coverage is Ned Batchelder's coverage.py tool.

NB: Implementing this would not be trivial by any means.

As pointed out by @Ira Baxter it is possible to implement.

like image 143
James Mills Avatar answered Sep 28 '22 06:09

James Mills