Add condition to results.json pass rate generation
method which returns 0 as the pass rate when the suite
is skipped, rather than causing a divide by 0 error.
Fixes: 9f8a257235ac ("dts: improve test run result statistics")
Signed-off-by: Dean Marx <[email protected]>
---
dts/framework/test_result.py | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/dts/framework/test_result.py b/dts/framework/test_result.py
index ba7c1c9804..aed20981b2 100644
--- a/dts/framework/test_result.py
+++ b/dts/framework/test_result.py
@@ -324,13 +324,15 @@ def generate_pass_rate_dict(self, test_run_summary) ->
dict[str, float]:
Returns:
A dictionary with the PASS/FAIL ratio of all test cases.
"""
- return {
- "PASS_RATE": (
- float(test_run_summary[Result.PASS.name])
- * 100
- / sum(test_run_summary[result.name] for result in Result if
result != Result.SKIP)
- )
- }
+ cases_not_skipped = sum(
+ test_run_summary[result.name] for result in Result if result !=
Result.SKIP
+ )
+ if cases_not_skipped == 0:
+ return {"PASS_RATE": 0.0}
+ else:
+ return {
+ "PASS_RATE": (float(test_run_summary[Result.PASS.name]) * 100
/ cases_not_skipped)
+ }
class DTSResult(BaseResult):
--
2.44.0