[TIP] branch coverage for ternary/guard/default

Matthew Desmarais matthew.desmarais at gmail.com
Wed Jun 13 07:30:49 PDT 2012


Hi there,

Instrumental (http://pypi.python.org/pypi/instrumental/0.3.1) is one
of the tools that uses AST transformations to gather coverage
information (as Ned mentioned). It should be able to produce the
result you're looking for in the ternary expression case at least,
although I know that it doesn't currently. I should be able to add
this pretty easily. Let me know off-list if you're interested in
trying it out and we can try to get you the information that you're
looking for.

Thanks,
Matthew

On Fri, May 25, 2012 at 7:45 PM, Ned Batchelder <ned at nedbatchelder.com> wrote:
> On 5/25/2012 6:31 PM, Jason Keene wrote:
>
> Hello,
>
> Is there a tool that can do branch coverage testing of ternary/guard/default
> expressions. Eg:
>
> 'happy path' if mostly_true() else 1/0
> mostly_true() or 1/0
> mostly_false() and 1/0
>
> So if the test suite doesn't hit the 1/0's then it will indicate partial
> coverage.  I'm new to branch coverage testing and testing python in general
> so sorry if this is a newb question.
>
> Jason
>
> Most of the existing coverage tools are based on sys.settrace(), which only
> reports lines being executed, so it provides no visibility into the
> inter-line execution like you want to get.  There are others based on AST
> transformations, but none of them have reached production-quality, they are
> experiments.
>
> I created a proof-of-concept of using settrace() to get bytecode-tracing
> rather than line tracing, but again, it's never been turned into a real
> tool, and in particular, it may not be possible to get useful reporting out
> of it.  If you are interested, it's here:
> http://nedbatchelder.com/blog/200804/wicked_hack_python_bytecode_tracing.html
>
> --Ned.
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
>



More information about the testing-in-python mailing list