From 3ac6e47bda1125dfa6bcf5a92693ed90cd248b24 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Sat, 26 Oct 2019 22:27:04 +0800 Subject: [PATCH] fix #707: duration stat error in multiple testsuites Thanks @lijuelijue and @plmmilove --- CHANGELOG.md | 4 ++++ httprunner/report.py | 22 ++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f9cd7f3..a6112afb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ - log httprunner version before running tests - remove unused import & code +**Fixed** + +- fix #707: duration stat error in multiple testsuites + ## 2.2.6 (2019-09-18) **Added** diff --git a/httprunner/report.py b/httprunner/report.py index d337de76..a3d775d4 100644 --- a/httprunner/report.py +++ b/httprunner/report.py @@ -54,11 +54,11 @@ def get_summary(result): } } summary["stat"]["successes"] = summary["stat"]["total"] \ - - summary["stat"]["failures"] \ - - summary["stat"]["errors"] \ - - summary["stat"]["skipped"] \ - - summary["stat"]["expectedFailures"] \ - - summary["stat"]["unexpectedSuccesses"] + - summary["stat"]["failures"] \ + - summary["stat"]["errors"] \ + - summary["stat"]["skipped"] \ + - summary["stat"]["expectedFailures"] \ + - summary["stat"]["unexpectedSuccesses"] summary["time"] = { 'start_at': result.start_at, @@ -80,10 +80,16 @@ def aggregate_stat(origin_stat, new_stat): for key in new_stat: if key not in origin_stat: origin_stat[key] = new_stat[key] + + elif key == "duration": + # duration = max_end_time - min_start_time + max_end_time = max(origin_stat["start_at"] + origin_stat["duration"], + new_stat["start_at"] + new_stat["duration"]) + min_start_time = min(origin_stat["start_at"], new_stat["start_at"]) + origin_stat["duration"] = max_end_time - min_start_time elif key == "start_at": - # start datetime , duration=current_time - min(stat_at) - origin_stat[key] = min(origin_stat[key], new_stat[key]) - origin_stat["duration"] = time.time() - origin_stat[key] + # start datetime + origin_stat["start_at"] = min(origin_stat["start_at"], new_stat["start_at"]) else: origin_stat[key] += new_stat[key]