Skip to content

Commit 8f4d404

Browse files
committed
refactor: a better way to filter coverage debug pybehave
1 parent a3f3841 commit 8f4d404

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

coverage/env.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99

1010
from typing import Any, Iterable, Tuple
1111

12+
# debug_info() at the bottom wants to show all the globals, but not imports.
13+
# Grab the global names here to know which names to not show. Nothing defined
14+
# above this line will be in the output.
15+
_UNINTERESTING_GLOBALS = list(globals())
16+
# These names also shouldn't be shown.
17+
_UNINTERESTING_GLOBALS += ["PYBEHAVIOR", "debug_info"]
18+
1219
# Operating systems.
1320
WINDOWS = sys.platform == "win32"
1421
LINUX = sys.platform.startswith("linux")
@@ -140,10 +147,7 @@ def debug_info() -> Iterable[Tuple[str, Any]]:
140147
"""Return a list of (name, value) pairs for printing debug information."""
141148
info = [
142149
(name, value) for name, value in globals().items()
143-
if not name.startswith("_") and
144-
name not in {"PYBEHAVIOR", "debug_info"} and
145-
not isinstance(value, type(os)) and
146-
not str(value).startswith("typing.")
150+
if not name.startswith("_") and name not in _UNINTERESTING_GLOBALS
147151
]
148152
info += [
149153
(name, value) for name, value in PYBEHAVIOR.__dict__.items()

tests/test_cmdline.py

+6
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,12 @@ def test_debug_pybehave(self) -> None:
318318
assert " CPYTHON:" in out
319319
assert " PYVERSION:" in out
320320
assert " pep626:" in out
321+
322+
# Some things that shouldn't appear..
323+
assert "typing." not in out # import from typing
324+
assert ": <" not in out # objects without a good repr
325+
326+
# It should report PYVERSION correctly.
321327
pyversion = re_line(r" PYVERSION:", out)
322328
vtuple = ast.literal_eval(pyversion.partition(":")[-1].strip())
323329
assert vtuple[:5] == sys.version_info

0 commit comments

Comments
 (0)