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.1.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.1-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: coverage_treemap-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 57b6e52bf2936cbe4f522d4924184f9d0fb2253b6a7913ab5c01d54ede432f84
MD5 454f66e01187b12446d2f957bc1b0ee7
BLAKE2b-256 a5b35853ed0415992a08bd10fa40b3464115f441b3767521a0bb94170829e085

See more details on using hashes here.

File details

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

File metadata

  • Download URL: coverage_treemap-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 17.6 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 db8380e683c5b1bf5d0bc737c6391c6e709883b923a69495a9a27c490144f726
MD5 27fe2024e09324273da2ae27a219fe55
BLAKE2b-256 f99ce58f0946bb061b4dc7c86fe088cd18cd5515a56f0e45e2a8c8907ae1d492

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