[TIP] branch coverage for ternary/guard/default
Ned Batchelder
ned at nedbatchelder.com
Fri May 25 16:45:46 PDT 2012
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20120525/71cde131/attachment.htm>
More information about the testing-in-python
mailing list