diff options
| author | Ned Batchelder <ned@nedbatchelder.com> | 2022-02-04 20:05:05 -0500 |
|---|---|---|
| committer | Ned Batchelder <ned@nedbatchelder.com> | 2022-02-06 11:09:53 -0500 |
| commit | 642647abdadea247c32d8dad8e5755f52238574c (patch) | |
| tree | c20650a43f3cbf4d8ef83ac52855861e748a2cc4 /coverage | |
| parent | bf99bb663940f203bee6d373f6b6f30840831fab (diff) | |
| download | python-coveragepy-git-642647abdadea247c32d8dad8e5755f52238574c.tar.gz | |
debug: add 'pybehave' debug information
It shows the behavior flags from coverage.env.
Diffstat (limited to 'coverage')
| -rw-r--r-- | coverage/control.py | 13 | ||||
| -rw-r--r-- | coverage/debug.py | 13 |
2 files changed, 24 insertions, 2 deletions
diff --git a/coverage/control.py b/coverage/control.py index 9dfa59fb..a3fda8d8 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -329,6 +329,19 @@ class Coverage: write_formatted_info(self._debug, header, info) wrote_any = True + if self._debug.should('pybehave'): + info = [ + (name, value) for name, value in env.__dict__.items() + if not name.startswith("_") and + name != "PYBEHAVIOR" and + not isinstance(value, type(os)) + ] + [ + (name, value) for name, value in env.PYBEHAVIOR.__dict__.items() + if not name.startswith("_") + ] + write_formatted_info(self._debug, "pybehave", sorted(info)) + wrote_any = True + if wrote_any: write_formatted_info(self._debug, "end", ()) diff --git a/coverage/debug.py b/coverage/debug.py index 74b59d0e..e6f93aa6 100644 --- a/coverage/debug.py +++ b/coverage/debug.py @@ -118,7 +118,10 @@ def info_formatter(info): for label, data in info: if data == []: data = "-none-" - if isinstance(data, (list, set, tuple)): + if isinstance(data, tuple) and len(repr(tuple(data))) < 30: + # Convert to tuple to scrub namedtuples. + yield "%*s: %r" % (label_len, label, tuple(data)) + elif isinstance(data, (list, set, tuple)): prefix = "%*s:" % (label_len, label) for e in data: yield "%*s %s" % (label_len+1, prefix, e) @@ -128,7 +131,13 @@ def info_formatter(info): def write_formatted_info(writer, header, info): - """Write a sequence of (label,data) pairs nicely.""" + """Write a sequence of (label,data) pairs nicely. + + `writer` has a .write(str) method. `header` is a string to start the + section. `info` is a sequence of (label, data) pairs, where label + is a str, and data can be a single value, or a list/set/tuple. + + """ writer.write(info_header(header)) for line in info_formatter(info): writer.write(" %s" % line) |
