From 2db5f12486410126ed597b9eaac958f6bef58cde Mon Sep 17 00:00:00 2001 From: WendyInXian Date: Fri, 6 Dec 2024 14:45:10 +0800 Subject: [PATCH] fix the incorrect elapsed time issue After robotframework 7.0, the time format of output.xml was changed, end_time is removed and replaced with elapsed, the merger method cannot handle new format correctly, only pick the elapsed time of first suite from the pabot_results as the total elapsed time. --- src/pabot/result_merger.py | 2 + .../output_with_latest_robot/first.xml | 43 +++++++++++++++++++ .../output_with_latest_robot/second.xml | 43 +++++++++++++++++++ .../output_with_latest_robot/third.xml | 43 +++++++++++++++++++ tests/test_resultmerger.py | 40 +++++++++++++++-- 5 files changed, 167 insertions(+), 4 deletions(-) create mode 100644 tests/outputs/output_with_latest_robot/first.xml create mode 100644 tests/outputs/output_with_latest_robot/second.xml create mode 100644 tests/outputs/output_with_latest_robot/third.xml diff --git a/src/pabot/result_merger.py b/src/pabot/result_merger.py index e7ab827d..6b407160 100644 --- a/src/pabot/result_merger.py +++ b/src/pabot/result_merger.py @@ -150,6 +150,8 @@ def merge_missing_tests(self, suite): def merge_time(self, suite): cur = self.current + if ROBOT_VERSION >= "7.0": + cur.elapsed_time = None cur.endtime = max([cur.endtime, suite.endtime]) cur.starttime = min([cur.starttime, suite.starttime]) diff --git a/tests/outputs/output_with_latest_robot/first.xml b/tests/outputs/output_with_latest_robot/first.xml new file mode 100644 index 00000000..01b285a0 --- /dev/null +++ b/tests/outputs/output_with_latest_robot/first.xml @@ -0,0 +1,43 @@ + + + + + + +this is first +this is first +Logs the given message with the given level. + + + +Slept 1 second. +1s +Pauses the test executed for the given time. + + + +yeah +yeah +Logs the given message with the given level. + + + + + + + + + + +All Tests + + + + +Tmp +Tmp.Tests + + + + + diff --git a/tests/outputs/output_with_latest_robot/second.xml b/tests/outputs/output_with_latest_robot/second.xml new file mode 100644 index 00000000..5b32d630 --- /dev/null +++ b/tests/outputs/output_with_latest_robot/second.xml @@ -0,0 +1,43 @@ + + + + + + +this is second +this is second +Logs the given message with the given level. + + + +Slept 1 second. +1s +Pauses the test executed for the given time. + + + +wohoo +wohoo +Logs the given message with the given level. + + + + + + + + + + +All Tests + + + + +Tmp +Tmp.Tests + + + + + diff --git a/tests/outputs/output_with_latest_robot/third.xml b/tests/outputs/output_with_latest_robot/third.xml new file mode 100644 index 00000000..29d7de2f --- /dev/null +++ b/tests/outputs/output_with_latest_robot/third.xml @@ -0,0 +1,43 @@ + + + + + + +this is third +this is third +Logs the given message with the given level. + + + +Slept 1 second. +1s +Pauses the test executed for the given time. + + + +bruut +bruut +Logs the given message with the given level. + + + + + + + + + + +All Tests + + + + +Tmp +Tmp.Tests + + + + + diff --git a/tests/test_resultmerger.py b/tests/test_resultmerger.py index 15280a42..6ecf900d 100644 --- a/tests/test_resultmerger.py +++ b/tests/test_resultmerger.py @@ -1,11 +1,8 @@ import unittest -import time import os -import tempfile -import shutil -import random import pabot.result_merger as result_merger from robot.result.visitor import ResultVisitor +from robot import __version__ as ROBOT_VERSION class ResultStats(ResultVisitor): @@ -68,6 +65,41 @@ def test_prefixing(self): self.assertEqual(result_merger.prefix(os.path.join("koo", "foo.bar")), "koo") self.assertEqual(result_merger.prefix("hui.txt"), "") + def test_elapsed_time(self): + if ROBOT_VERSION >= "7.0": + result = result_merger.merge( + [ + "tests/outputs/output_with_latest_robot/first.xml", + "tests/outputs/output_with_latest_robot/second.xml", + "tests/outputs/output_with_latest_robot/third.xml", + ], + {}, + "root", + [], + ) + visitor = ResultStats() + result.visit(visitor) + self.assertEqual("Tmp", result.suite.name) + self.assertEqual(1573, result.suite.elapsedtime) + self.assertEqual("Tests", result.suite.suites[0].name) + self.assertEqual(1474, result.suite.suites[0].elapsedtime) + else: + result = result_merger.merge( + [ + "tests/outputs/first.xml", + "tests/outputs/second.xml", + "tests/outputs/third.xml", + ], + {}, + "root", + [], + ) + visitor = ResultStats() + result.visit(visitor) + self.assertEqual("Tmp", result.suite.name) + self.assertEqual(1036, result.suite.elapsedtime) + self.assertEqual("Tests", result.suite.suites[0].name) + self.assertEqual(1010, result.suite.suites[0].elapsedtime) if __name__ == "__main__": unittest.main()