We have a simple AssertTrue function used in our python project and I wanted to modify the output it provides to print the code statement from which it was called. The code looks something like this:
1 import traceback
2
3 def AssertTrue(expr, reason=None):
4 print traceback.format_stack()[-2]
5
6 AssertTrue(1 == 2,
7 reason='One is not equal to two')
The output:
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)