Skip to content

Commit

Permalink
refactor: a better way to filter coverage debug pybehave
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Jan 1, 2023
1 parent a3f3841 commit 8f4d404
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 8 additions & 4 deletions coverage/env.py
Expand Up @@ -9,6 +9,13 @@

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")
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions tests/test_cmdline.py
Expand Up @@ -318,6 +318,12 @@ def test_debug_pybehave(self) -> None:
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
Expand Down

0 comments on commit 8f4d404

Please sign in to comment.