coverage.py JSON, format 3

The JSON report coverage.py 7.6 and later write with coverage json, format version 3, as a JSON Schema.

Read by pyEDAA.Reports.CodeCoverage.CoveragePy.Document for a report stating meta.format 3 - see coverage.py JSON.

coverage.py publishes no schema of its JSON report. This one is reverse-engineered from coverage.py’s coverage/jsonreport.py (version 7.16): format 3 adds the regions functions and classes to a file. A field a later coverage.py added - e.g. percent_statements_covered - is optional; an unknown field is rejected. Format 2 has its own schema: CoveragePy-2.schema.json.

Download

CoveragePy-3.schema.json (5.1 kiB)

Validate a report

check-jsonschema --schemafile CoveragePy-3.schema.json coverage.json

Source

  1{
  2	"$schema": "https://json-schema.org/draft/2020-12/schema",
  3	"$id": "https://edaa-org.github.io/pyEDAA.Reports/Schemas/CoveragePy-3.schema.json",
  4	"title": "coverage.py JSON report, format 3",
  5	"description": "The JSON report coverage.py 7.6 and later write with 'coverage json', format version 3. Reverse-engineered from coverage.py's 'coverage/jsonreport.py' (7.16): format 3 adds the regions 'functions' and 'classes' to a file. Fields a later coverage.py added - e.g. 'percent_statements_covered' - are optional.",
  6	"type": "object",
  7	"required": ["meta", "files", "totals"],
  8	"properties": {
  9		"meta": {
 10			"description": "How and when the report was written.",
 11			"type": "object",
 12			"required": ["format", "version", "timestamp", "branch_coverage", "show_contexts"],
 13			"properties": {
 14				"format":          {"description": "Version of the report format.", "const": 3},
 15				"version":         {"description": "Version of coverage.py.", "type": "string"},
 16				"timestamp":       {"description": "Time the report was written, ISO 8601.", "type": "string"},
 17				"branch_coverage": {"description": "Whether branch coverage was measured.", "type": "boolean"},
 18				"show_contexts":   {"description": "Whether the lines' contexts are listed.", "type": "boolean"}
 19			}
 20		},
 21		"files": {
 22			"description": "The measured files, by path relative to the directory coverage.py ran in.",
 23			"type": "object",
 24			"additionalProperties": {"$ref": "#/$defs/File"}
 25		},
 26		"totals": {"$ref": "#/$defs/Summary"}
 27	},
 28	"$defs": {
 29		"LineNumbers": {
 30			"type": "array",
 31			"items": {"type": "integer", "minimum": 1}
 32		},
 33		"Arcs": {
 34			"description": "Branches as pairs of source and destination line; a negative destination exits a code object.",
 35			"type": "array",
 36			"items": {
 37				"type": "array",
 38				"prefixItems": [{"type": "integer"}, {"type": "integer"}],
 39				"minItems": 2,
 40				"maxItems": 2
 41			}
 42		},
 43		"Contexts": {
 44			"description": "The contexts which ran a line, by line number.",
 45			"type": "object",
 46			"additionalProperties": {"type": "array", "items": {"type": "string"}}
 47		},
 48		"Summary": {
 49			"description": "Counters and percentages, as coverage.py computed them.",
 50			"type": "object",
 51			"required": ["covered_lines", "num_statements", "percent_covered", "missing_lines", "excluded_lines"],
 52			"properties": {
 53				"covered_lines":                      {"type": "integer", "minimum": 0},
 54				"num_statements":                     {"type": "integer", "minimum": 0},
 55				"percent_covered":                    {"type": "number",  "minimum": 0, "maximum": 100},
 56				"percent_covered_display":            {"type": "string"},
 57				"missing_lines":                      {"type": "integer", "minimum": 0},
 58				"excluded_lines":                     {"type": "integer", "minimum": 0},
 59				"percent_statements_covered":         {"type": "number",  "minimum": 0, "maximum": 100},
 60				"percent_statements_covered_display": {"type": "string"},
 61				"num_branches":                       {"type": "integer", "minimum": 0},
 62				"num_partial_branches":               {"type": "integer", "minimum": 0},
 63				"covered_branches":                   {"type": "integer", "minimum": 0},
 64				"missing_branches":                   {"type": "integer", "minimum": 0},
 65				"percent_branches_covered":           {"type": "number",  "minimum": 0, "maximum": 100},
 66				"percent_branches_covered_display":   {"type": "string"}
 67			},
 68			"additionalProperties": false
 69		},
 70		"Lines": {
 71			"description": "The lines and branches of a file or a region.",
 72			"type": "object",
 73			"required": ["executed_lines", "summary", "missing_lines", "excluded_lines"],
 74			"properties": {
 75				"executed_lines":    {"$ref": "#/$defs/LineNumbers"},
 76				"summary":           {"$ref": "#/$defs/Summary"},
 77				"missing_lines":     {"$ref": "#/$defs/LineNumbers"},
 78				"excluded_lines":    {"$ref": "#/$defs/LineNumbers"},
 79				"executed_branches": {"$ref": "#/$defs/Arcs"},
 80				"missing_branches":  {"$ref": "#/$defs/Arcs"},
 81				"contexts":          {"$ref": "#/$defs/Contexts"}
 82			}
 83		},
 84		"Region": {
 85			"description": "A function or class of a file, by qualified name; the name '' holds the lines outside of every region of this kind.",
 86			"allOf": [{"$ref": "#/$defs/Lines"}],
 87			"required": ["start_line"],
 88			"properties": {
 89				"executed_lines":    true,
 90				"summary":           true,
 91				"missing_lines":     true,
 92				"excluded_lines":    true,
 93				"executed_branches": true,
 94				"missing_branches":  true,
 95				"contexts":          true,
 96				"start_line":        {"type": "integer", "minimum": 1}
 97			},
 98			"additionalProperties": false
 99		},
100		"File": {
101			"description": "A measured file: its lines and branches, and its functions and classes.",
102			"allOf": [{"$ref": "#/$defs/Lines"}],
103			"properties": {
104				"executed_lines":    true,
105				"summary":           true,
106				"missing_lines":     true,
107				"excluded_lines":    true,
108				"executed_branches": true,
109				"missing_branches":  true,
110				"contexts":          true,
111				"functions":         {"type": "object", "additionalProperties": {"$ref": "#/$defs/Region"}},
112				"classes":           {"type": "object", "additionalProperties": {"$ref": "#/$defs/Region"}}
113			},
114			"additionalProperties": false
115		}
116	}
117}