summaryrefslogtreecommitdiff
path: root/coverage/debug.py
diff options
context:
space:
mode:
Diffstat (limited to 'coverage/debug.py')
-rw-r--r--coverage/debug.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/coverage/debug.py b/coverage/debug.py
index d63a9070..f491a0f7 100644
--- a/coverage/debug.py
+++ b/coverage/debug.py
@@ -24,13 +24,12 @@ os = isolate_module(os)
# This is a list of forced debugging options.
FORCED_DEBUG = []
-# A hack for debugging testing in sub-processes.
-_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 +70,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 +170,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.