File "/tmp/fisken.py", line 7, in <module>
reason='One is not equal to two')

I'm wondering why traceback.format_stack only gives me the code on line 7. The statement starts on line 6 and the expression I would like to see in the output is also on that same line. Doesn't traceback handle multi-line function calls?

(Never mind that there are better ways to do AssertTrue(...). I'm just wondering why traceback.format_stack (and .extract_stack) does not behave as I expected it to)

1 Answer
1

Many functions are tens or even (horrors) hundreds of lines long. If traceback did print the whole function, then stack traces would become incomprehensibly long. So I guess what you are seeing is an attempt to keep things clean and minimal.

I guess you are right about the assumption of length. The traceback function will only print the one line to limit the output. The code you provided looks like a beautiful hack. Thanks... :-)
–
Vegar WesterlundJul 17 '12 at 12:52

I would of course like to get only the assert statement and not the entire function as a string.
–
Vegar WesterlundJul 17 '12 at 13:00

That's beyond my hacking skills at the moment. If I think of something, I'll get back to you :)
–
Andrew AlcockJul 18 '12 at 1:12