summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.rst2
-rw-r--r--coverage/control.py13
-rw-r--r--coverage/debug.py13
-rw-r--r--doc/cmd.rst5
4 files changed, 30 insertions, 3 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 81f29bc8..d391dc9e 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -20,7 +20,7 @@ development at the same time, such as 4.5.x and 5.0.
Unreleased
----------
-Nothing yet.
+- Debug: added ``pybehave`` to the list of :ref:`cmd_run_debug` options.
.. _changes_631:
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)
diff --git a/doc/cmd.rst b/doc/cmd.rst
index afc9c27a..9b710a3e 100644
--- a/doc/cmd.rst
+++ b/doc/cmd.rst
@@ -981,6 +981,9 @@ of operation to log:
* ``process``: show process creation information, and changes in the current
directory.
+* ``pybehave``: show the values of `internal flags <env.py_>`_ describing the
+ behavior of the current version of Python.
+
* ``self``: annotate each debug message with the object printing the message.
* ``sql``: log the SQL statements used for recording data.
@@ -991,6 +994,8 @@ of operation to log:
* ``trace``: print every decision about whether to trace a file or not. For
files not being traced, the reason is also given.
+.. _env.py: https://github.com/nedbat/coveragepy/blob/master/coverage/env.py
+
Debug options can also be set with the ``COVERAGE_DEBUG`` environment variable,
a comma-separated list of these options.