coverage.py JSON, format 2

The JSON report coverage.py 7.4.1 to 7.5 write with coverage json, format version 2, as a JSON Schema.

Read by pyEDAA.Reports.CodeCoverage.CoveragePy.Document for a report stating meta.format 2 - 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) and its change log: format 2 added meta.format. A file has no regions functions and classes - format 3 adds them -, a summary no separate percentages of statements and branches - coverage.py 7.12 adds them to format 3. An unknown field is rejected. Format 3 has its own schema: CoveragePy-3.schema.json.

Download

CoveragePy-2.schema.json (3.9 kiB)

Validate a report

check-jsonschema --schemafile CoveragePy-2.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-2.schema.json",
 4	"title": "coverage.py JSON report, format 2",
 5	"description": "The JSON report coverage.py 7.4.1 to 7.5 write with 'coverage json', format version 2. Reverse-engineered from coverage.py's 'coverage/jsonreport.py' (7.16) and its change log: format 2 added 'meta.format'; a file has no regions 'functions' and 'classes', a summary no separate percentages of statements and branches.",
 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": 2},
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				"num_branches":            {"type": "integer", "minimum": 0},
60				"num_partial_branches":    {"type": "integer", "minimum": 0},
61				"covered_branches":        {"type": "integer", "minimum": 0},
62				"missing_branches":        {"type": "integer", "minimum": 0}
63			},
64			"additionalProperties": false
65		},
66		"Lines": {
67			"description": "The lines and branches of a file or a region.",
68			"type": "object",
69			"required": ["executed_lines", "summary", "missing_lines", "excluded_lines"],
70			"properties": {
71				"executed_lines":    {"$ref": "#/$defs/LineNumbers"},
72				"summary":           {"$ref": "#/$defs/Summary"},
73				"missing_lines":     {"$ref": "#/$defs/LineNumbers"},
74				"excluded_lines":    {"$ref": "#/$defs/LineNumbers"},
75				"executed_branches": {"$ref": "#/$defs/Arcs"},
76				"missing_branches":  {"$ref": "#/$defs/Arcs"},
77				"contexts":          {"$ref": "#/$defs/Contexts"}
78			}
79		},
80		"File": {
81			"description": "A measured file: its lines and branches.",
82			"allOf": [{"$ref": "#/$defs/Lines"}],
83			"properties": {
84				"executed_lines":    true,
85				"summary":           true,
86				"missing_lines":     true,
87				"excluded_lines":    true,
88				"executed_branches": true,
89				"missing_branches":  true,
90				"contexts":          true
91			},
92			"additionalProperties": false
93		}
94	}
95}