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
commit90a95fdd608dc94d052a1b79667d60bb41f9dd31 (patch)
treefb8890b51c07fd2b6132813411e8f71a1ab4496b /coverage/debug.py
parent9566b1329f16a185f0f750f878dc2d2a90953e59 (diff)
downloadpython-coveragepy-90a95fdd608dc94d052a1b79667d60bb41f9dd31.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 5b41bc4..fbffc56 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())