diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2016-09-24 19:08:50 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2016-09-24 19:08:50 -0400 |
commit | 0c642aea0842b72868293b2e9bbb34ed2aecb6ff (patch) | |
tree | 452c2ac40687757afa2f83553d274b4da47ee6fa | |
parent | 798c38e9f6d6598dc59ea6f5d71fce96cdeb7ae7 (diff) | |
download | python-coveragepy-git-0c642aea0842b72868293b2e9bbb34ed2aecb6ff.tar.gz |
Clean up and test the callers debugging info
-rw-r--r-- | coverage/debug.py | 8 | ||||
-rw-r--r-- | tests/test_debug.py | 13 |
2 files changed, 17 insertions, 4 deletions
diff --git a/coverage/debug.py b/coverage/debug.py index 3d67c611..d173f43f 100644 --- a/coverage/debug.py +++ b/coverage/debug.py @@ -49,7 +49,7 @@ class DebugControl(object): msg = "pid %5d: %s" % (os.getpid(), msg) self.output.write(msg+"\n") if callers and self.should('callers'): - dump_stack_frames(out=self.output) + dump_stack_frames(out=self.output, skip=1) self.output.flush() def write_formatted_info(self, header, info): @@ -109,10 +109,10 @@ def short_stack(limit=None, skip=0): return "\n".join("%30s : %s @%d" % (t[3], t[1], t[2]) for t in stack) -def dump_stack_frames(limit=None, out=None): # pragma: debugging +def dump_stack_frames(limit=None, out=None, skip=0): """Print a summary of the stack to stdout, or some place else.""" out = out or sys.stdout - out.write(short_stack(limit=limit)) + out.write(short_stack(limit=limit, skip=skip+1)) out.write("\n") @@ -121,7 +121,7 @@ def log(msg, stack=False): # pragma: debugging with open("/tmp/covlog.txt", "a") as f: f.write("{pid}: {msg}\n".format(pid=os.getpid(), msg=msg)) if stack: - dump_stack_frames(out=f) + dump_stack_frames(out=f, skip=1) def enable_aspectlib_maybe(): diff --git a/tests/test_debug.py b/tests/test_debug.py index 8309395b..e80beecf 100644 --- a/tests/test_debug.py +++ b/tests/test_debug.py @@ -103,6 +103,19 @@ class DebugTraceTest(CoverageTest): self.assertTrue(lines_matching(out_lines, pid_prefix + "Tracing ")) self.assertTrue(lines_matching(out_lines, pid_prefix + "Not tracing ")) + def test_debug_trace_callers(self): + out_lines = self.f1_debug_output(["trace", "callers"]) + + # For every "Tracing" or "Not tracing" message, there should be a stack + # trace with a line like "_should_trace : /Users/ned/coverage/control.py @616" + trace_messages = lines_matching(out_lines, r"^(T|Not t)racing ") + should_trace_pattern = r"\s+_should_trace : .*coverage[/\\]control.py @\d+$" + should_trace_frames = lines_matching(out_lines, should_trace_pattern) + self.assertEqual(len(trace_messages), len(should_trace_frames)) + + # The very last line should be a _should_trace frame. + self.assertRegex(out_lines[-1], should_trace_pattern) + def test_debug_config(self): out_lines = self.f1_debug_output(["config"]) |