summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2023-01-01 07:42:00 -0500
committerNed Batchelder <ned@nedbatchelder.com>2023-01-01 07:42:00 -0500
commit8f4d404c8f9044ea1c3bf2479236f51d7706cb76 (patch)
treea3b5d2d58edaa15a37bff9aa2f1b4fcbba39dcdb
parenta3f3841b746a1789ff8f7fea0cc0715c45770996 (diff)
downloadpython-coveragepy-git-8f4d404c8f9044ea1c3bf2479236f51d7706cb76.tar.gz
refactor: a better way to filter `coverage debug pybehave`
-rw-r--r--coverage/env.py12
-rw-r--r--tests/test_cmdline.py6
2 files changed, 14 insertions, 4 deletions
diff --git a/coverage/env.py b/coverage/env.py
index 0b01f3e7..c6c1ed13 100644
--- a/coverage/env.py
+++ b/coverage/env.py
@@ -9,6 +9,13 @@ import sys
from typing import Any, Iterable, Tuple
+# debug_info() at the bottom wants to show all the globals, but not imports.
+# Grab the global names here to know which names to not show. Nothing defined
+# above this line will be in the output.
+_UNINTERESTING_GLOBALS = list(globals())
+# These names also shouldn't be shown.
+_UNINTERESTING_GLOBALS += ["PYBEHAVIOR", "debug_info"]
+
# Operating systems.
WINDOWS = sys.platform == "win32"
LINUX = sys.platform.startswith("linux")
@@ -140,10 +147,7 @@ def debug_info() -> Iterable[Tuple[str, Any]]:
"""Return a list of (name, value) pairs for printing debug information."""
info = [
(name, value) for name, value in globals().items()
- if not name.startswith("_") and
- name not in {"PYBEHAVIOR", "debug_info"} and
- not isinstance(value, type(os)) and
- not str(value).startswith("typing.")
+ if not name.startswith("_") and name not in _UNINTERESTING_GLOBALS
]
info += [
(name, value) for name, value in PYBEHAVIOR.__dict__.items()
diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py
index 85e99ad5..96bd3bbf 100644
--- a/tests/test_cmdline.py
+++ b/tests/test_cmdline.py
@@ -318,6 +318,12 @@ class CmdLineTest(BaseCmdLineTest):
assert " CPYTHON:" in out
assert " PYVERSION:" in out
assert " pep626:" in out
+
+ # Some things that shouldn't appear..
+ assert "typing." not in out # import from typing
+ assert ": <" not in out # objects without a good repr
+
+ # It should report PYVERSION correctly.
pyversion = re_line(r" PYVERSION:", out)
vtuple = ast.literal_eval(pyversion.partition(":")[-1].strip())
assert vtuple[:5] == sys.version_info