Skip to content

Commit 642647a

Browse files
committed
debug: add 'pybehave' debug information
It shows the behavior flags from coverage.env.
1 parent bf99bb6 commit 642647a

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

CHANGES.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ development at the same time, such as 4.5.x and 5.0.
2020
Unreleased
2121
----------
2222

23-
Nothing yet.
23+
- Debug: added ``pybehave`` to the list of :ref:`cmd_run_debug` options.
2424

2525

2626
.. _changes_631:

coverage/control.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,19 @@ def _write_startup_debug(self):
329329
write_formatted_info(self._debug, header, info)
330330
wrote_any = True
331331

332+
if self._debug.should('pybehave'):
333+
info = [
334+
(name, value) for name, value in env.__dict__.items()
335+
if not name.startswith("_") and
336+
name != "PYBEHAVIOR" and
337+
not isinstance(value, type(os))
338+
] + [
339+
(name, value) for name, value in env.PYBEHAVIOR.__dict__.items()
340+
if not name.startswith("_")
341+
]
342+
write_formatted_info(self._debug, "pybehave", sorted(info))
343+
wrote_any = True
344+
332345
if wrote_any:
333346
write_formatted_info(self._debug, "end", ())
334347

coverage/debug.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ def info_formatter(info):
118118
for label, data in info:
119119
if data == []:
120120
data = "-none-"
121-
if isinstance(data, (list, set, tuple)):
121+
if isinstance(data, tuple) and len(repr(tuple(data))) < 30:
122+
# Convert to tuple to scrub namedtuples.
123+
yield "%*s: %r" % (label_len, label, tuple(data))
124+
elif isinstance(data, (list, set, tuple)):
122125
prefix = "%*s:" % (label_len, label)
123126
for e in data:
124127
yield "%*s %s" % (label_len+1, prefix, e)
@@ -128,7 +131,13 @@ def info_formatter(info):
128131

129132

130133
def write_formatted_info(writer, header, info):
131-
"""Write a sequence of (label,data) pairs nicely."""
134+
"""Write a sequence of (label,data) pairs nicely.
135+
136+
`writer` has a .write(str) method. `header` is a string to start the
137+
section. `info` is a sequence of (label, data) pairs, where label
138+
is a str, and data can be a single value, or a list/set/tuple.
139+
140+
"""
132141
writer.write(info_header(header))
133142
for line in info_formatter(info):
134143
writer.write(" %s" % line)

doc/cmd.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,9 @@ of operation to log:
981981
* ``process``: show process creation information, and changes in the current
982982
directory.
983983

984+
* ``pybehave``: show the values of `internal flags <env.py_>`_ describing the
985+
behavior of the current version of Python.
986+
984987
* ``self``: annotate each debug message with the object printing the message.
985988

986989
* ``sql``: log the SQL statements used for recording data.
@@ -991,6 +994,8 @@ of operation to log:
991994
* ``trace``: print every decision about whether to trace a file or not. For
992995
files not being traced, the reason is also given.
993996

997+
.. _env.py: https://github.com/nedbat/coveragepy/blob/master/coverage/env.py
998+
994999
Debug options can also be set with the ``COVERAGE_DEBUG`` environment variable,
9951000
a comma-separated list of these options.
9961001

0 commit comments

Comments
 (0)