feat: add coverage.py JSON report support (pytest-json-coverage-path)#286
Conversation
Adds a third coverage input format alongside TXT and XML: the JSON report from `coverage json`. New src/parseJson.ts mirrors the XML parser, reusing the existing toHtml/DataFromXml rendering pipeline, and supports branch coverage, missing-line ranges, and partial-branch arrows (line->target, line->exit). The missing column matches `coverage report -m` (a branch arc whose destination is an already-missing line is omitted). - New input `pytest-json-coverage-path`; parser precedence JSON > XML > TXT - Wired into index.ts, cli.ts, and multiFiles.ts (monorepo, .json detection) - Reuses formatCoverPercent from parseXml; finite-percentage guard - Tests + fixtures (data/coverage_1.json, data/coverage_2.json); README + action.yml docs Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
CodeAnt AI is reviewing your PR. |
Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PR Summary by QodoAdd coverage.py JSON parsing via pytest-json-coverage-path input
AI Description
Diagram
High-Level Assessment
Files changed (17)
|
|
CodeAnt AI finished reviewing your PR. |
Code Review by Qodo
Context used✅ Tickets:
🎫 [Feature]: Use and parse JSON report 1. Total cover missing %
|
There was a problem hiding this comment.
Pull request overview
Adds support for parsing coverage.py’s coverage json output as a third coverage input format, integrating it into the existing rendering pipeline so badges/tables remain consistent with the current TXT/XML output.
Changes:
- Introduces
pytest-json-coverage-pathand routes coverage parsing with precedence JSON > XML > TXT. - Adds a JSON parser (
src/parseJson.ts) that maps coverage.py JSON into the existingtoHtml/DataFromXmltable+badge renderer (including branch/missing details). - Updates documentation, fixtures, tests, and rebuilds
dist.
Reviewed changes
Copilot reviewed 15 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/types.d.ts | Adds covJsonFile to the shared Options type. |
| src/parseXml.ts | Exports formatCoverPercent for reuse by the JSON parser. |
| src/parseJson.ts | New JSON parser producing the same report shape as XML to reuse existing rendering. |
| src/multiFiles.ts | Adds .json detection for monorepo multiple-files mode and routes to JSON parser. |
| src/index.ts | Adds new action input pytest-json-coverage-path and selects JSON parser with highest precedence. |
| src/cli.ts | Updates local CLI harness to allow testing JSON parsing. |
| README.md | Documents the new pytest-json-coverage-path input and JSON usage example. |
| action.yml | Adds the new JSON input and documents JSON as a supported multiple-files format. |
| tests/parseXml.test.ts | Updates test options to include covJsonFile. |
| tests/parse.test.ts | Updates test options to include covJsonFile. |
| tests/multiFiles.test.ts | Updates test options to include covJsonFile. |
| tests/junitXml.test.ts | Updates test options to include covJsonFile. |
| tests/parseJson.test.ts | Adds focused tests for JSON parsing behavior and internal helpers. |
| data/coverage_1.json | Adds JSON fixture (no branch coverage) for tests. |
| data/coverage_2.json | Adds JSON fixture (with branch coverage) for tests. |
| CLAUDE.md | Updates repo documentation to reflect JSON support and precedence. |
| dist/index.js | Rebuilds bundled action output to include JSON support. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Bump version 1.9.0 -> 1.10.0 and add CHANGELOG entry for the new pytest-json-coverage-path input. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
WalkthroughThis PR adds JSON coverage parsing alongside the existing XML path. A new Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/index.ts (1)
444-457: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winStale
covXmlFile-only group name for the new JSON path.This block assumes an object-shaped
coverage(with.cover) always came from XML, so it hardcodescore.startGroup(options.covXmlFile). SincegetCoverageJsonReport(wired in at Line 320-321) now also returns this shape whileoptions.covXmlFileis empty, JSON-only users getcore.startGroup('')— a blank/unlabeled log group instead of showing their coverage file. The comment above it is also now stale (pytest-xml-coverage-pathonly).This mirrors the fallback chain already used in
src/multiFiles.ts(covXmlFile || covJsonFile || covFile), which wasn't applied here.🔧 Proposed fix
- // support for output for `pytest-xml-coverage-path` + // support for output for `pytest-xml-coverage-path` / `pytest-json-coverage-path` if ( coverage && typeof coverage === 'object' && (coverage as { cover?: string }).cover ) { - core.startGroup(options.covXmlFile); + core.startGroup(options.covXmlFile || options.covJsonFile); core.info(`coverage: ${(coverage as { cover: string }).cover}`);
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e42853ba-87d9-4b42-a267-4b9a5759ef1d
⛔ Files ignored due to path filters (1)
dist/index.jsis excluded by!**/dist/**
📒 Files selected for processing (16)
CLAUDE.mdREADME.md__tests__/junitXml.test.ts__tests__/multiFiles.test.ts__tests__/parse.test.ts__tests__/parseJson.test.ts__tests__/parseXml.test.tsaction.ymldata/coverage_1.jsondata/coverage_2.jsonsrc/cli.tssrc/index.tssrc/multiFiles.tssrc/parseJson.tssrc/parseXml.tssrc/types.d.ts
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2742f12d-bf96-436e-a71f-047b05edee1e
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (2)
CHANGELOG.mdpackage.json
✅ Files skipped from review due to trivial changes (1)
- package.json
There was a problem hiding this comment.
1 issue found and verified against the latest diff
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Dismissed because Cubic found issues in a newer review.
User description
Closes #282.
Adds a third coverage input format alongside TXT and XML: the JSON report from
coverage json, via a newpytest-json-coverage-pathinput.src/parseJson.tsmirrors the XML parser and reuses the existingtoHtml/DataFromXmlrendering pipeline (badge, folder-grouped table, colors).line->target,line->exit). The Missing column matchescoverage report -m(an arc whose destination is an already-missing line is omitted).percent_covered; reusesformatCoverPercentwith a finite-percentage guard.xml-skip-covered; supports monorepomultiple-files(.jsondetection).action.ymldocumented;distrebuilt.Validated end-to-end in
api-testing-example: the full matrix (all existing TXT/XML/feature cases + new JSON cases) passes with no regressions, and comments update in place on re-run. Supersedes the auto-generated #283.🤖 Generated with Claude Code
Summary by cubic
Adds first-class support for coverage.py JSON reports via a new
pytest-json-coverage-pathinput, with JSON now preferred over XML/TXT. Released as v1.10.0; output (HTML, badges, colors) matches existing reports.New Features
pytest-json-coverage-pathforcoverage json; precedence is JSON > XML > TXT.line->target,line->exit), omitting arcs to already-missing lines.xml-skip-covered; monorepomultiple-filesnow detects.json.formatCoverPercent; JSON uses coverage.pypercent_coveredwith a finite guard.README.md,action.yml), tests/fixtures,dist, andCHANGELOG.mdupdated; version bumped to 1.10.0.Migration
coverage json -o coverage.json, then setpytest-json-coverage-path.Written for commit eeb248b. Summary will update on new commits.
CodeAnt-AI Description
Add support for coverage.json reports
What Changed
coverage jsonas the coverage source.jsonfiles and use the same comment and badge output as the existing coverage formatsImpact
✅ Use coverage.json without converting to XML✅ Fewer setup steps for Python coverage comments✅ Consistent coverage comments in monorepos💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.