summaryrefslogtreecommitdiff
path: root/coverage/debug.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2015-07-11 08:49:20 -0400
committerNed Batchelder <ned@nedbatchelder.com>2015-07-11 08:49:20 -0400
commit1bbf2cd42d6d86ac71bb429fef320af92f1ef3d6 (patch)
tree6b20aeffbc31cb07e7427948f9998daa12fa51c1 /coverage/debug.py
parent72d59223f8fc096576ee4fe9c6b5684ee066123a (diff)
downloadpython-coveragepy-git-1bbf2cd42d6d86ac71bb429fef320af92f1ef3d6.tar.gz
If __file__ disagrees with the frame, use the frame info. Fixes #380.
Diffstat (limited to 'coverage/debug.py')
-rw-r--r--coverage/debug.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/coverage/debug.py b/coverage/debug.py
index 5b41bc40..fbffc569 100644
--- a/coverage/debug.py
+++ b/coverage/debug.py
@@ -1,5 +1,6 @@
"""Control of and utilities for debugging."""
+import inspect
import os
@@ -66,3 +67,25 @@ def info_formatter(info):
prefix = ""
else:
yield "%*s: %s" % (label_len, label, data)
+
+
+def short_stack(): # pragma: debugging
+ """Return a string summarizing the call stack.
+
+ The string is multi-line, with one line per stack frame. Each line shows
+ the function name, the file name, and the line number:
+
+ ...
+ start_import_stop : /Users/ned/coverage/trunk/tests/coveragetest.py @95
+ import_local_file : /Users/ned/coverage/trunk/tests/coveragetest.py @81
+ import_local_file : /Users/ned/coverage/trunk/coverage/backward.py @159
+ ...
+
+ """
+ stack = inspect.stack()[:0:-1]
+ return "\n".join("%30s : %s @%d" % (t[3], t[1], t[2]) for t in stack)
+
+
+def dump_stack_frames(): # pragma: debugging
+ """Print a summary of the stack to stdout."""
+ print(short_stack())