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
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 ...
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With