Skip to content

Commit 6391a6d

Browse files
committed
#397: Fixed handling empty coverage
1 parent 0e157f8 commit 6391a6d

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import datetime
22
import json
33
import re
4+
import sys
45
from collections import defaultdict
56
from dataclasses import (
67
asdict,
@@ -13,7 +14,7 @@
1314
from functools import singledispatch
1415
from inspect import cleandoc
1516
from pathlib import Path
16-
from subprocess import run
17+
import subprocess
1718
from tempfile import TemporaryDirectory
1819
from typing import (
1920
Any,
@@ -99,16 +100,27 @@ class Report:
99100
security: Rating
100101
technical_debt: Rating
101102

102-
103103
def total_coverage(file: Union[str, Path]) -> float:
104104
with TemporaryDirectory() as tmpdir:
105105
tmp_dir = Path(tmpdir)
106106
report = tmp_dir / "coverage.json"
107-
run(
107+
p = subprocess.run(
108108
["coverage", "json", f"--data-file={file}", "-o", f"{report}"],
109109
capture_output=True,
110-
check=True,
110+
check=False,
111+
encoding="utf-8",
111112
)
113+
stdout = p.stdout.strip()
114+
if (p.returncode == 1) and (stdout == "No data to report."):
115+
print(
116+
f'The following command'
117+
f' returned non-zero exit status {p.returncode}:\n'
118+
f' {" ".join(p.args)}\n'
119+
f'{stdout}\n'
120+
'Returning total coverage 100 %.',
121+
file=sys.stderr,
122+
)
123+
return 100.0
112124
with open(report, encoding="utf-8") as r:
113125
data = json.load(r)
114126
total: float = data["totals"]["percent_covered"]

0 commit comments

Comments
 (0)