Skip to content

Generate Coverage

This guide shows you how to generate and view code coverage reports.

  1. Navigate to the API directory

    Terminal window
    cd idx-api
  2. Generate coverage with HTML report

    Terminal window
    make test-coverage
  3. Open the report in your browser

    Terminal window
    open reports/coverage/index.html
Terminal window
cd idx-api
# Coverage for agent router only
uv run pytest tests/ --cov=idx_api.routers.agents --cov-report=html
# Coverage for multiple modules
uv run pytest tests/ \
--cov=idx_api.routers.agents \
--cov=idx_api.routers.brokerages \
--cov-report=html
# Coverage for entire package with terminal output
uv run pytest tests/ --cov=idx_api --cov-report=term-missing

For quick checks without opening HTML reports:

Terminal window
# Show missing lines in terminal
uv run pytest tests/ --cov=idx_api --cov-report=term-missing
# Just show the summary
uv run pytest tests/ --cov=idx_api --cov-report=term

Some code should be intentionally excluded from coverage:

# pragma: no cover - for code that shouldn't be tested
if __name__ == "__main__": # pragma: no cover
run()

Configure global exclusions in pyproject.toml:

[tool.coverage.run]
omit = [
"*/tests/*",
"*/__pycache__/*",
]

After generating coverage reports, publish them to the documentation site:

Terminal window
# Generate and publish in one step
make test-publish
# Or separately
make test-coverage
make publish-docs

The coverage report will be available at: /reports/coverage/index.html