Skip to content

Commit 9d6891b

Browse files
ckunkiArBridgeman
andauthored
#397: Fixed handling empty coverage (#398)
* #397: Fixed handling empty coverage * project:fix * Ignored failure when reporting empty coverage * moved double dash to front * Updated template for file .gitignore Co-authored-by: Ariel Schulz <43442541+ArBridgeman@users.noreply.github.com>
1 parent 0e157f8 commit 9d6891b

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

.github/workflows/report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ jobs:
5252
poetry run -- nox -s project:report -- --format markdown >> $GITHUB_STEP_SUMMARY
5353
poetry run -- nox -s dependency:licenses >> $GITHUB_STEP_SUMMARY
5454
echo -e "\n\n# Coverage\n" >> $GITHUB_STEP_SUMMARY
55-
poetry run coverage report -- --format markdown >> $GITHUB_STEP_SUMMARY
55+
poetry run -- coverage report --format markdown >> $GITHUB_STEP_SUMMARY || true
5656
poetry run -- tbx lint pretty-print >> $GITHUB_STEP_SUMMARY
5757
poetry run -- tbx security pretty-print .security.json >> $GITHUB_STEP_SUMMARY

doc/changes/unreleased.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
# Unreleased
2+
3+
## Bugfixes
4+
5+
* #397: Fix handling empty coverage

exasol/toolbox/metrics.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import datetime
22
import json
33
import re
4+
import subprocess
5+
import sys
46
from collections import defaultdict
57
from dataclasses import (
68
asdict,
@@ -13,7 +15,6 @@
1315
from functools import singledispatch
1416
from inspect import cleandoc
1517
from pathlib import Path
16-
from subprocess import run
1718
from tempfile import TemporaryDirectory
1819
from typing import (
1920
Any,
@@ -104,11 +105,23 @@ def total_coverage(file: Union[str, Path]) -> float:
104105
with TemporaryDirectory() as tmpdir:
105106
tmp_dir = Path(tmpdir)
106107
report = tmp_dir / "coverage.json"
107-
run(
108+
p = subprocess.run(
108109
["coverage", "json", f"--data-file={file}", "-o", f"{report}"],
109110
capture_output=True,
110-
check=True,
111+
check=False,
112+
encoding="utf-8",
111113
)
114+
stdout = p.stdout.strip()
115+
if (p.returncode == 1) and (stdout == "No data to report."):
116+
print(
117+
f"The following command"
118+
f" returned non-zero exit status {p.returncode}:\n"
119+
f' {" ".join(p.args)}\n'
120+
f"{stdout}\n"
121+
"Returning total coverage 100 %.",
122+
file=sys.stderr,
123+
)
124+
return 100.0
112125
with open(report, encoding="utf-8") as r:
113126
data = json.load(r)
114127
total: float = data["totals"]["percent_covered"]

exasol/toolbox/templates/github/workflows/report.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
# Errors during copying are ignored because they are checked in the next step
3232
cp .coverage ../ || true
3333
cp lint-python3.9/.lint.txt ../ || true
34-
cp lint-python3.9/.lint.txt ../ || true
34+
cp lint-python3.9/.lint.json ../ || true
3535
cp security-python3.9/.security.json ../ || true
3636
3737
- name: Validate Artifacts
@@ -52,6 +52,6 @@ jobs:
5252
poetry run -- nox -s project:report -- --format markdown >> $GITHUB_STEP_SUMMARY
5353
poetry run -- nox -s dependency:licenses >> $GITHUB_STEP_SUMMARY
5454
echo -e "\n\n# Coverage\n" >> $GITHUB_STEP_SUMMARY
55-
poetry run coverage report -- --format markdown >> $GITHUB_STEP_SUMMARY
55+
poetry run -- coverage report --format markdown >> $GITHUB_STEP_SUMMARY || true
5656
poetry run -- tbx lint pretty-print >> $GITHUB_STEP_SUMMARY
5757
poetry run -- tbx security pretty-print .security.json >> $GITHUB_STEP_SUMMARY

project-template/{{cookiecutter.repo_name}}/.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,10 @@ doc/api
142142
itde/
143143

144144
# Emacs
145-
TAGS
145+
/TAGS
146+
147+
# PTB
148+
/.lint.json
149+
/.lint.txt
150+
/.security.json
151+

0 commit comments

Comments
 (0)