[Python-Dev] Tracing at a more granular level (branch coverage)

m h sesquile at gmail.com
Tue Apr 1 21:02:13 CEST 2008

Howdy Folks-

I hope this is not too off topic.  Sadly the current sys.settrace only
allows tracing at the line level.  This isn't sufficient to do branch
and path coverage.  The main problem is that many boolean operations
can appear on a single line, and so you can't be sure which
conditional branch was taken using the current tracing method.

After speaking about code complexity/testing at Pycon [0], with a few
people there, and seeing a few people have made some strides or shown
interested in metrics/code graphs/flow and branch coverage I think
that there is interest in this.

One proposed method of getting branch coverage was to use Dalke's
Python4Ply [1] to translate code so that all branches occur on their
own line.  Then using line coverage on that and converting it back to
branch coverage of the original code.

The maintainer of coverage.py suggested that we look into patching
python instead to trace at a more granular level.  His feeling was
that there would be too many corner cases and the translation would
get hairy quite quickly.

Sadly in my 8 years of python experience I've yet to touch any c based
guts of python.  I'm looking for advice on how to get finer grain
tracing with sys.settrace.

Any advice or suggestions?  There is a quorum of people (at least 5
others) who would be very interested in this functionality because it
could lead to some cool tools built on top of it.  (With the end goal
that python code be cleaner, simpler and better tested).

thanks much,

-matt harrison

0 - http://panela.blog-city.com/pycon_2008_managing_complexity_slides.htm
1 - http://www.dalkescientific.com/Python/python4ply.html

More information about the Python-Dev mailing list