infra: base-runner: add filtering to python cov reports (#9698)

This is to avoid reporting coverage on files that are essentially not
part of a given project, which butchers the summarised coverage stats at
the moment.

Signed-off-by: David Korczynski <david@adalogics.com>

Signed-off-by: David Korczynski <david@adalogics.com>
This commit is contained in:
DavidKorczynski 2023-02-17 14:45:39 +00:00 committed by GitHub
parent d39c930d5b
commit 2f0f64b2b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 0 deletions

View File

@ -25,6 +25,23 @@ from coverage.cmdline import main as coverage_main
from coverage.data import CoverageData
def should_exclude_file(filepath):
"""Returns whether the path should be excluded from the coverage report."""
# Skip all atheris code
if "atheris" in filepath:
return True
# Filter out all standard python libraries
if '/usr/local/lib/python' in filepath and 'site-packages' not in filepath:
return True
# Avoid all PyInstaller modules.
if 'PyInstaller' in filepath:
return True
return False
def translate_lines(cov_data, new_cov_data, all_file_paths):
"""
Translate lines in a .coverage file created by coverage.py such that
@ -40,6 +57,8 @@ def translate_lines(cov_data, new_cov_data, all_file_paths):
# Check if this file exists in our file paths:
for local_file_path in all_file_paths:
if should_exclude_file(local_file_path):
continue
if local_file_path.endswith(stripped_py_file_path):
print('Found matching: %s' % (local_file_path))
new_cov_data.add_lines(