The Python Oracle

Python tracing and conditional jumps

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Future Grid Looping

--

Chapters
00:00 Question
02:38 Accepted answer (Score 4)
04:08 Answer 2 (Score 6)
04:51 Thank you

--

Full question
https://stackoverflow.com/questions/6943...

Question links:
[concolic engine]: http://en.wikipedia.org/wiki/Concolic_te...

Answer 1 links:
[Wicked hack: Python bytecode tracing]: http://nedbatchelder.com/blog/200804/wic...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #testing #branch #trace

#avk47



ANSWER 1

Score 6


There is no information in the trace facility about the last branch taken.

What I did to implement branch coverage measurement in coverage.py is to keep a record for each stack frame of the last line executed, then the next time the trace function is called, I can record a pair of line numbers which form a from-to arc of execution.

About finer-grained tracing: you can trick the Python interpreter into giving you byte code information. My experiment in this is described here: Wicked hack: Python bytecode tracing

I'd be very interested to see how this work progresses!