From d20cc5279d682931a9b09d43300b605c4ac6c20d Mon Sep 17 00:00:00 2001 From: Daniel Perez Date: Tue, 27 Jul 2021 01:21:49 +0100 Subject: [PATCH] fix: do not remove contract from coverage report if a function is missing statements or branches The previous behavior expects all functions to have a report for both statements and branches. If not, it removes the whole contract from the coverage report. While the assumption seems reasonable, some functions seem to only have either one of statements or branches, ending up in removing contracts that would otherwise contain useful coverage information. This is related to #1087 and should at least be a partial fix to it --- CHANGELOG.md | 1 + brownie/test/output.py | 17 ++++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea3283f9e..b7a5d4d4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ This changelog format is based on [Keep a Changelog](https://keepachangelog.com/ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased](https://github.com/eth-brownie/brownie) +- Fix issue with missing contracts in coverage report ## [1.16.0](https://github.com/eth-brownie/brownie/tree/v1.16.0) - 2021-08-08 ### Added diff --git a/brownie/test/output.py b/brownie/test/output.py index 5b68cb89a..f2a950357 100644 --- a/brownie/test/output.py +++ b/brownie/test/output.py @@ -223,11 +223,14 @@ def _split_by_fn(build, coverage_eval): def _split(coverage_eval, coverage_map, key): results = {} - for fn, map_ in coverage_map["statements"][key].items(): - results[fn] = [[i for i in map_ if int(i) in coverage_eval[0]], [], []] - for fn, map_ in coverage_map["branches"][key].items(): - results[fn][1] = [i for i in map_ if int(i) in coverage_eval[1]] - results[fn][2] = [i for i in map_ if int(i) in coverage_eval[2]] + branches = coverage_map["branches"][key] + statements = coverage_map["statements"][key] + for fn in branches.keys() & statements.keys(): + results[fn] = [ + [i for i in statements[fn] if int(i) in coverage_eval[0]], + [i for i in branches[fn] if int(i) in coverage_eval[1]], + [i for i in branches[fn] if int(i) in coverage_eval[2]], + ] return results @@ -235,7 +238,7 @@ def _statement_totals(coverage_eval, coverage_map, exclude_contracts): result = {} count, total = 0, 0 for path, fn in [(k, x) for k, v in coverage_eval.items() for x in v]: - if fn.split(".")[0] in exclude_contracts: + if fn.split(".")[0] in exclude_contracts or fn not in coverage_eval[path]: continue count += len(coverage_eval[path][fn][0]) total += len(coverage_map[path][fn]) @@ -249,7 +252,7 @@ def _branch_totals(coverage_eval, coverage_map, exclude_contracts): for path, fn in [(k, x) for k, v in coverage_map.items() for x in v]: if fn.split(".")[0] in exclude_contracts: continue - if path not in coverage_eval: + if path not in coverage_eval or fn not in coverage_eval[path]: true, false = 0, 0 else: true = len(coverage_eval[path][fn][2])