summaryrefslogtreecommitdiff
path: root/coverage/jsonreport.py
diff options
context:
space:
mode:
authorChristoph Blessing <33834216+cblessing24@users.noreply.github.com>2022-08-18 12:58:29 +0200
committerNed Batchelder <ned@nedbatchelder.com>2022-09-29 06:34:58 -0400
commitaabc54031a673e2f789620a993a90197a36f0e95 (patch)
tree7ea56e32eada3119894d249b31a5142e0a47c1ec /coverage/jsonreport.py
parenta59fc4485df1191a8efaeae92e780e9f0710484e (diff)
downloadpython-coveragepy-git-aabc54031a673e2f789620a993a90197a36f0e95.tar.gz
feat: include branches taken and missed in JSON report. #1425
Added more branches to the code whose coverage is checked. Add branch details to json report The json report now includes for each branch which branches have been executed, missed and what the percentage of covered branches was. Add exiting branch arc to json report test Update branch details format Executed and missing branch arcs are stored in the fields named 'executed_branches' and 'missing_branches' respectively. Both fields contain a list of two element lists. The first element represents the source line number and the second one the target line number. Exit branches have their target line number set to 0. Fix linting errors
Diffstat (limited to 'coverage/jsonreport.py')
-rw-r--r--coverage/jsonreport.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/coverage/jsonreport.py b/coverage/jsonreport.py
index 43edc452..7ca468e3 100644
--- a/coverage/jsonreport.py
+++ b/coverage/jsonreport.py
@@ -102,4 +102,17 @@ class JsonReporter:
'covered_branches': nums.n_executed_branches,
'missing_branches': nums.n_missing_branches,
})
+ reported_file['executed_branches'] = list(
+ _convert_branch_arcs(analysis.executed_branch_arcs())
+ )
+ reported_file['missing_branches'] = list(
+ _convert_branch_arcs(analysis.missing_branch_arcs())
+ )
return reported_file
+
+
+def _convert_branch_arcs(branch_arcs):
+ """Convert branch arcs to a list of two-element tuples."""
+ for source, targets in branch_arcs.items():
+ for target in targets:
+ yield source, target if target != -1 else 0