Skip to main content

Render a treemap visualization from a coverage.py JSON report.

Project description

coverage-treemap

A small tool that turns a coverage.py JSON report into an SVG (or standalone HTML) treemap — so you can see at a glance which parts of your codebase are well-tested and which aren't.

coverage-treemap example output: an SVG treemap where each rectangle is a source file, sized by statement count and colored by coverage percentage

Inspired by go-cover-treemap.

Ships two entry points:

  • a standalone CLI for rendering from an existing coverage.json,
  • a pytest plugin that writes the treemap at the end of a test run.

Requirements

  • Python 3.13+

Install

pip install coverage-treemap
# or, for one-off CLI use:
uvx coverage-treemap coverage.json -o coverage.html

CLI

  1. Generate a coverage JSON report:

    pytest --cov=. --cov-report=json:coverage.json
    
  2. Render the treemap:

    # HTML with interactive hover tooltips (recommended)
    coverage-treemap coverage.json -o coverage.html
    
    # Static SVG
    coverage-treemap coverage.json -o coverage.svg
    
    # Pipe to stdout
    coverage-treemap coverage.json > coverage.svg
    

Output format is auto-detected from the file extension; override with --format svg|html|auto.

Pytest plugin

Once installed, pytest picks up the plugin automatically. Pass --cov-treemap=PATH and a treemap is written at the end of the session:

pytest --cov-treemap=coverage.html

The plugin starts its own coverage.Coverage() under the hood, so you don't need --cov=. or pytest-cov installed. Source/omit rules come from your .coveragerc or [tool.coverage.run] section as usual. If pytest-cov is active, the plugin reuses its coverage instance instead of double-measuring.

Plugin options

Option Default Description
--cov-treemap off Output path. .html / .svg format inferred from extension.
--cov-treemap-group-by package package or directory.
--cov-treemap-depth 2 Depth for --cov-treemap-group-by package.

CLI options

Option Default Description
--group-by package package — group by first N path components. directory — full recursive tree.
--depth 2 For --group-by package: how many leading path components form the group key.
--width 1200 Canvas width in pixels.
--height 1800 Canvas height in pixels.
--format auto svg, html, or auto (infer from -o extension).
-o, --output stdout Output path.

--group-by package with --depth

For a repo laid out like mypkg/subpkg/file.py:

  • --depth 1 groups by top-level package (mypkg).
  • --depth 2 (default) groups by sub-package (mypkg/subpkg).
  • --depth 3 goes one level deeper.

--group-by directory

Renders the full filesystem tree recursively — every directory becomes a nested rectangle. Useful for exploring deep hierarchies.

Filtering what shows up

The tool reports on whatever is in the coverage data. Exclude noise (migrations, vendored code, settings, tests) via coverage.py's own config, not via the treemap:

# pyproject.toml
[tool.coverage.run]
branch = true
omit = [
    "*/migrations/*",
    "*/tests/*",
    "*/settings/*",
    "vendored/*",
]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coverage_treemap-0.1.0.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

coverage_treemap-0.1.0-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file coverage_treemap-0.1.0.tar.gz.

File metadata

  • Download URL: coverage_treemap-0.1.0.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for coverage_treemap-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8228f42f3a7664f38d336c09686171ad0d6a3b7fbc5b1ef611f0562b03e6d0b7
MD5 3e7b5e2de43ccca443e00bb3c918f3fa
BLAKE2b-256 7e2e499a7d321d19a8362b13705a168093f4db3edd27ea1b464ee52feded1265

See more details on using hashes here.

File details

Details for the file coverage_treemap-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: coverage_treemap-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for coverage_treemap-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06dc20d110dbba6728796dfbe91f0c5eeaa0ee1057941ae5ef44719e336fdd84
MD5 48f36b6595d479922251fb41ac136268
BLAKE2b-256 dfccb51f64af22c37c96c49f37c88e9f2ddad61f3bd8b5e83fcd723db519bf1a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page