Ned Batchelder | 26 May 2012 01:45
Favicon
Gravatar

Re: branch coverage for ternary/guard/default

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

Gmane