summaryrefslogtreecommitdiff
path: root/coverage/debug.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2018-08-04 10:03:47 -0400
committerNed Batchelder <ned@nedbatchelder.com>2018-08-04 10:03:47 -0400
commitf1561b04f58fdd04b86d2ed0dc858a1222752b02 (patch)
treeac0a2aa1d1a1b19582bea26d1858e3fb6f522d0f /coverage/debug.py
parent2f0d57856550ef7ad248e4e6127700bdabb91e7d (diff)
downloadpython-coveragepy-git-f1561b04f58fdd04b86d2ed0dc858a1222752b02.tar.gz
Improved debugging
Diffstat (limited to 'coverage/debug.py')
-rw-r--r--coverage/debug.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/coverage/debug.py b/coverage/debug.py
index d63a9070..fd27c731 100644
--- a/coverage/debug.py
+++ b/coverage/debug.py
@@ -31,6 +31,8 @@ _TEST_NAME_FILE = "" # "/tmp/covtest.txt"
class DebugControl(object):
"""Control and output for debugging."""
+ show_repr_attr = False # For SimpleRepr
+
def __init__(self, options, output):
"""Configure the options and output file for debugging."""
self.options = list(options) + FORCED_DEBUG
@@ -71,6 +73,10 @@ class DebugControl(object):
`msg` is the line to write. A newline will be appended.
"""
+ if self.should('self'):
+ caller_self = inspect.stack()[1][0].f_locals.get('self')
+ if caller_self is not None:
+ msg = "[self: {!r}] {}".format(caller_self, msg)
self.output.write(msg+"\n")
if self.should('callers'):
dump_stack_frames(out=self.output, skip=1)
@@ -167,6 +173,17 @@ def add_pid_and_tid(text):
return text
+class SimpleRepr(object):
+ """A mixin implementing a simple __repr__."""
+ def __repr__(self):
+ show_attrs = ((k, v) for k, v in self.__dict__.items() if getattr(v, "show_repr_attr", True))
+ return "<{klass} @0x{id:x} {attrs}>".format(
+ klass=self.__class__.__name__,
+ id=id(self),
+ attrs=" ".join("{}={!r}".format(k, v) for k, v in show_attrs),
+ )
+
+
def filter_text(text, filters):
"""Run `text` through a series of filters.