[TIP] new (python 2.6) fn: gettrace

m h sesquile at gmail.com
Wed Jan 23 14:34:16 PST 2008


On Jan 23, 2008 3:21 PM, Titus Brown <titus at caltech.edu> wrote:
>
> On Wed, Jan 23, 2008 at 03:18:44PM -0700, m h wrote:
> -> On Jan 23, 2008 1:39 PM, Titus Brown <titus at caltech.edu> wrote:
> -> > Hi folks,
> -> >
> -> > I thought code coverage aficionados might be interested to hear that a
> -> > new function, sys.gettrace, has been added into python 2.6:
> -> >
> -> >         http://bugs.python.org/issue1648
> ->
> -> I was crossing my fingers that this might provide more granularity
> -> than line level coverage....
> ->
> -> I guess I need to file a bug...
>
> Explain?

If you want to do path coverage you need to be able to mark every path
through the code.
The current method of line coverage doesn't allow one to trace short
circuiting in boolean operations.

Here's some example code:

baz = "junk"
foo = "bar"
if foo == "bar" or baz == "bar":
  #do something

Now how many paths are there through that code?  1? 2?

I bet most people would say 1.  Perhaps some might say 2.  But neither
are correct.

There's actually 3.  There's one for the foo == "bar", another for
when bar =="bar" and a third for the implied else.

Line coverage will only be able to tell me one of those paths.  That's
because the current tracing functionality only supports the "line"
level.  There is no way to detect if the "or" is ever hit or if it is
only short circuited.

Makes sense?

-matt



More information about the testing-in-python mailing list