[TIP] Coverage.py 4.1b2: re-written branch measurement

Ned Batchelder ned at nedbatchelder.com
Sat Jan 23 17:08:15 PST 2016


I've just release Coverage.py 4.1b2: 
https://pypi.python.org/pypi/coverage/4.1b2

This version includes a completely rewritten branch analysis 
implementation.  In 4.0 and before, the possible branches were 
determined by examining the bytecode.  Now, we use the AST.  This has 
resulted in a much more predictable assessment of possible branches, 
closing a handful of long-standing bugs.

But it also means that some things that were not considered possible 
branches now are.  And in particular, they may be flagged as missing 
branches.  If you use branch coverage, I would be interested in your 
feedback.  There are some cases where it is not clear what the right 
behavior is.

For example:

     try:                    # 1
         ...                 # 2
     except ValueError:      # 3
         ...                 # 4
     finally:                # 5
         ...                 # 6

     try:                    # 8
         ...                 # 9
     except:                 # 10
         ...                 # 11
     finally:                # 12
         ...                 # 13

In the first block of code, there's a branch from line 3 to line 6, in 
the case of an exception other than ValueError.  Should coverage.py flag 
that as missing if such an exception never happens?  Right now it does.  
In the second block of code, coverage.py understands that line 10 can 
never jump to 13, because there is no exception that would skip line 11.

Try it, let me know what you think: 
https://pypi.python.org/pypi/coverage/4.1b2

--Ned.



More information about the testing-in-python mailing list