Skip to content

Commit

Permalink
append the condition to check the legacyoutput option
Browse files Browse the repository at this point in the history
  • Loading branch information
WendyInXian committed Dec 9, 2024
1 parent 7ca5761 commit 68b0299
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/pabot/result_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@


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
self._skip_until = None
self._tests_root_name = tests_root_name
self._prefix = ""
self._out_dir = out_dir
self.legacy_output = legacy_output

self._patterns = []
regexp_template = (
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
35 changes: 28 additions & 7 deletions tests/test_resultmerger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -93,6 +113,7 @@ def test_elapsed_time(self):
{},
"root",
[],
True
)
visitor = ResultStats()
result.visit(visitor)
Expand Down

0 comments on commit 68b0299

Please sign in to comment.