From 2db5f12486410126ed597b9eaac958f6bef58cde Mon Sep 17 00:00:00 2001 From: WendyInXian Date: Fri, 6 Dec 2024 14:45:10 +0800 Subject: [PATCH 1/2] 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() From 68b0299444779c7aacd12f3155b749e7fe140619 Mon Sep 17 00:00:00 2001 From: WendyInXian Date: Mon, 9 Dec 2024 22:22:14 +0800 Subject: [PATCH 2/2] append the condition to check the legacyoutput option --- src/pabot/result_merger.py | 9 ++++++--- tests/test_resultmerger.py | 35 ++++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/pabot/result_merger.py b/src/pabot/result_merger.py index 6b407160..3f59a227 100644 --- a/src/pabot/result_merger.py +++ b/src/pabot/result_merger.py @@ -35,7 +35,7 @@ class ResultMerger(SuiteVisitor): - def __init__(self, result, tests_root_name, out_dir, copied_artifacts): + def __init__(self, result, tests_root_name, out_dir, copied_artifacts, legacy_output): self.root = result.suite self.errors = result.errors self.current = None @@ -43,6 +43,7 @@ def __init__(self, result, tests_root_name, out_dir, copied_artifacts): self._tests_root_name = tests_root_name self._prefix = "" self._out_dir = out_dir + self.legacy_output = legacy_output self._patterns = [] regexp_template = ( @@ -150,7 +151,7 @@ def merge_missing_tests(self, suite): def merge_time(self, suite): cur = self.current - if ROBOT_VERSION >= "7.0": + if ROBOT_VERSION >= "7.0" and not self.legacy_output: cur.elapsed_time = None cur.endtime = max([cur.endtime, suite.endtime]) cur.starttime = min([cur.starttime, suite.starttime]) @@ -224,13 +225,14 @@ def merge_groups( invalid_xml_callback, out_dir, copied_artifacts, + legacy_output ): merged = [] for group in group_by_root( results, critical_tags, non_critical_tags, invalid_xml_callback ).values(): base = group[0] - merger = ResultMerger(base, tests_root_name, out_dir, copied_artifacts) + merger = ResultMerger(base, tests_root_name, out_dir, copied_artifacts, legacy_output) for out in group: merger.merge(out) merged.append(base) @@ -261,6 +263,7 @@ def merge( invalid_xml_callback, settings.output_directory, copied_artifacts, + rebot_options.get('legacyoutput') ) if len(merged) == 1: if not merged[0].suite.doc: diff --git a/tests/test_resultmerger.py b/tests/test_resultmerger.py index 6ecf900d..031f9409 100644 --- a/tests/test_resultmerger.py +++ b/tests/test_resultmerger.py @@ -66,8 +66,9 @@ def test_prefixing(self): self.assertEqual(result_merger.prefix("hui.txt"), "") def test_elapsed_time(self): + # output.xml generated based on robotframework >= 7.0 without --legacyoutput option if ROBOT_VERSION >= "7.0": - result = result_merger.merge( + result_1 = result_merger.merge( [ "tests/outputs/output_with_latest_robot/first.xml", "tests/outputs/output_with_latest_robot/second.xml", @@ -77,13 +78,32 @@ def test_elapsed_time(self): "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) + visitor_1 = ResultStats() + result_1.visit(visitor_1) + self.assertEqual("Tmp", result_1.suite.name) + self.assertEqual(1573, result_1.suite.elapsedtime) + self.assertEqual("Tests", result_1.suite.suites[0].name) + self.assertEqual(1474, result_1.suite.suites[0].elapsedtime) + + # output.xml generated based on robotframework >=7.0 with --legacyoutput option + result_2 = result_merger.merge( + [ + "tests/outputs/first.xml", + "tests/outputs/second.xml", + "tests/outputs/third.xml", + ], + {'legacyoutput': True}, + "root", + [], + ) + visitor_2 = ResultStats() + result_2.visit(visitor_2) + self.assertEqual("Tmp", result_2.suite.name) + self.assertEqual(1036, result_2.suite.elapsedtime) + self.assertEqual("Tests", result_2.suite.suites[0].name) + self.assertEqual(1010, result_2.suite.suites[0].elapsedtime) else: + # output.xml generated based on robotframework < 7.0 result = result_merger.merge( [ "tests/outputs/first.xml", @@ -93,6 +113,7 @@ def test_elapsed_time(self): {}, "root", [], + True ) visitor = ResultStats() result.visit(visitor)