diff --git a/.github/workflows/report.yml b/.github/workflows/report.yml index eb176da08..b1670ed7c 100644 --- a/.github/workflows/report.yml +++ b/.github/workflows/report.yml @@ -52,6 +52,6 @@ jobs: poetry run -- nox -s project:report -- --format markdown >> $GITHUB_STEP_SUMMARY poetry run -- nox -s dependency:licenses >> $GITHUB_STEP_SUMMARY echo -e "\n\n# Coverage\n" >> $GITHUB_STEP_SUMMARY - poetry run coverage report -- --format markdown >> $GITHUB_STEP_SUMMARY + poetry run -- coverage report --format markdown >> $GITHUB_STEP_SUMMARY || true poetry run -- tbx lint pretty-print >> $GITHUB_STEP_SUMMARY poetry run -- tbx security pretty-print .security.json >> $GITHUB_STEP_SUMMARY diff --git a/doc/changes/unreleased.md b/doc/changes/unreleased.md index 79e701b84..92059e1e8 100644 --- a/doc/changes/unreleased.md +++ b/doc/changes/unreleased.md @@ -1 +1,5 @@ # Unreleased + +## Bugfixes + +* #397: Fix handling empty coverage diff --git a/exasol/toolbox/metrics.py b/exasol/toolbox/metrics.py index b5f57874e..11872692f 100644 --- a/exasol/toolbox/metrics.py +++ b/exasol/toolbox/metrics.py @@ -1,6 +1,8 @@ import datetime import json import re +import subprocess +import sys from collections import defaultdict from dataclasses import ( asdict, @@ -13,7 +15,6 @@ from functools import singledispatch from inspect import cleandoc from pathlib import Path -from subprocess import run from tempfile import TemporaryDirectory from typing import ( Any, @@ -104,11 +105,23 @@ def total_coverage(file: Union[str, Path]) -> float: with TemporaryDirectory() as tmpdir: tmp_dir = Path(tmpdir) report = tmp_dir / "coverage.json" - run( + p = subprocess.run( ["coverage", "json", f"--data-file={file}", "-o", f"{report}"], capture_output=True, - check=True, + check=False, + encoding="utf-8", ) + stdout = p.stdout.strip() + if (p.returncode == 1) and (stdout == "No data to report."): + print( + f"The following command" + f" returned non-zero exit status {p.returncode}:\n" + f' {" ".join(p.args)}\n' + f"{stdout}\n" + "Returning total coverage 100 %.", + file=sys.stderr, + ) + return 100.0 with open(report, encoding="utf-8") as r: data = json.load(r) total: float = data["totals"]["percent_covered"] diff --git a/exasol/toolbox/templates/github/workflows/report.yml b/exasol/toolbox/templates/github/workflows/report.yml index 12b67cc39..b7a513232 100644 --- a/exasol/toolbox/templates/github/workflows/report.yml +++ b/exasol/toolbox/templates/github/workflows/report.yml @@ -31,7 +31,7 @@ jobs: # Errors during copying are ignored because they are checked in the next step cp .coverage ../ || true cp lint-python3.9/.lint.txt ../ || true - cp lint-python3.9/.lint.txt ../ || true + cp lint-python3.9/.lint.json ../ || true cp security-python3.9/.security.json ../ || true - name: Validate Artifacts @@ -52,6 +52,6 @@ jobs: poetry run -- nox -s project:report -- --format markdown >> $GITHUB_STEP_SUMMARY poetry run -- nox -s dependency:licenses >> $GITHUB_STEP_SUMMARY echo -e "\n\n# Coverage\n" >> $GITHUB_STEP_SUMMARY - poetry run coverage report -- --format markdown >> $GITHUB_STEP_SUMMARY + poetry run -- coverage report --format markdown >> $GITHUB_STEP_SUMMARY || true poetry run -- tbx lint pretty-print >> $GITHUB_STEP_SUMMARY poetry run -- tbx security pretty-print .security.json >> $GITHUB_STEP_SUMMARY diff --git a/project-template/{{cookiecutter.repo_name}}/.gitignore b/project-template/{{cookiecutter.repo_name}}/.gitignore index fdfb6de9f..ca472841c 100644 --- a/project-template/{{cookiecutter.repo_name}}/.gitignore +++ b/project-template/{{cookiecutter.repo_name}}/.gitignore @@ -142,4 +142,10 @@ doc/api itde/ # Emacs -TAGS +/TAGS + +# PTB +/.lint.json +/.lint.txt +/.security.json +