diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2018-08-24 07:13:42 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2018-08-24 07:13:42 -0400 |
commit | c4b2392dd51b7f976972afb00f01d4618c523cff (patch) | |
tree | 7c77b420d4eec7ac628393663c67c0e9bc2c66f7 /coverage/debug.py | |
parent | 8a337f91e6444c027771741a56636a56389706e3 (diff) | |
parent | dd5b0cc88ebe4528abaa7cdf0b3fd516fb1f7e01 (diff) | |
download | python-coveragepy-git-c4b2392dd51b7f976972afb00f01d4618c523cff.tar.gz |
Merge branch 'nedbat/data-sqlite'
Diffstat (limited to 'coverage/debug.py')
-rw-r--r-- | coverage/debug.py | 20 |
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. |