diff --git a/src/pabot/result_merger.py b/src/pabot/result_merger.py index e7ab827d..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,6 +151,8 @@ def merge_missing_tests(self, suite): def merge_time(self, suite): cur = self.current + 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]) @@ -222,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) @@ -259,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/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..031f9409 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,62 @@ 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): + # output.xml generated based on robotframework >= 7.0 without --legacyoutput option + if ROBOT_VERSION >= "7.0": + result_1 = 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_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", + "tests/outputs/second.xml", + "tests/outputs/third.xml", + ], + {}, + "root", + [], + True + ) + 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()