Skip to content

Commit

Permalink
Merge pull request #605 from WendyInXian/main
Browse files Browse the repository at this point in the history
fix the incorrect elapsed time issue
  • Loading branch information
mkorpela authored Dec 14, 2024
2 parents 7d90370 + 68b0299 commit 6ae40b8
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 6 deletions.
9 changes: 7 additions & 2 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,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])

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
43 changes: 43 additions & 0 deletions tests/outputs/output_with_latest_robot/first.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<robot generator="Robot 7.0.1 (Python 3.11.1 on darwin)" generated="2024-12-06T09:41:12.425254" rpa="false" schemaversion="5">
<suite id="s1" name="Tmp" source="/Users/mkorpela/workspace/pabot/tmp">
<suite id="s1-s1" name="Tests" source="/Users/mkorpela/workspace/pabot/tmp/tests.robot">
<test id="s1-s1-t1" name="First" line="4">
<kw name="Log" owner="BuiltIn">
<msg time="2024-12-06T09:41:12.583145" level="INFO">this is first</msg>
<arg>this is first</arg>
<doc>Logs the given message with the given level.</doc>
<status status="PASS" start="2024-12-06T09:41:12.582148" elapsed="0.000997"/>
</kw>
<kw name="Sleep" owner="BuiltIn">
<msg time="2024-12-06T09:41:13.599800" level="INFO">Slept 1 second.</msg>
<arg>1s</arg>
<doc>Pauses the test executed for the given time.</doc>
<status status="PASS" start="2024-12-06T09:41:12.584151" elapsed="1.016646"/>
</kw>
<kw name="Log" owner="BuiltIn">
<msg time="2024-12-06T09:41:13.604820" level="INFO">yeah</msg>
<arg>yeah</arg>
<doc>Logs the given message with the given level.</doc>
<status status="PASS" start="2024-12-06T09:41:13.603813" elapsed="0.002005"/>
</kw>
<status status="PASS" start="2024-12-06T09:41:12.578940" elapsed="1.026878"/>
</test>
<status status="PASS" start="2024-12-06T09:41:12.571947" elapsed="1.041865"/>
</suite>
<status status="PASS" start="2024-12-06T09:41:12.482939" elapsed="1.137409"/>
</suite>
<statistics>
<total>
<stat pass="1" fail="0" skip="0">All Tests</stat>
</total>
<tag>
</tag>
<suite>
<stat pass="1" fail="0" skip="0" id="s1" name="Tmp">Tmp</stat>
<stat pass="1" fail="0" skip="0" id="s1-s1" name="Tests">Tmp.Tests</stat>
</suite>
</statistics>
<errors>
</errors>
</robot>
43 changes: 43 additions & 0 deletions tests/outputs/output_with_latest_robot/second.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<robot generator="Robot 7.0.1 (Python 3.11.1 on darwin)" generated="2024-12-06T09:41:12.597260" rpa="false" schemaversion="5">
<suite id="s1" name="Tmp" source="/Users/mkorpela/workspace/pabot/tmp">
<suite id="s1-s1" name="Tests" source="/Users/mkorpela/workspace/pabot/tmp/tests.robot">
<test id="s1-s1-t1" name="Second" line="9">
<kw name="Log" owner="BuiltIn">
<msg time="2024-12-06T09:41:12.849548" level="INFO">this is second</msg>
<arg>this is second</arg>
<doc>Logs the given message with the given level.</doc>
<status status="PASS" start="2024-12-06T09:41:12.848548" elapsed="0.002000"/>
</kw>
<kw name="Sleep" owner="BuiltIn">
<msg time="2024-12-06T09:41:14.038911" level="INFO">Slept 1 second.</msg>
<arg>1s</arg>
<doc>Pauses the test executed for the given time.</doc>
<status status="PASS" start="2024-12-06T09:41:12.851549" elapsed="1.187362"/>
</kw>
<kw name="Log" owner="BuiltIn">
<msg time="2024-12-06T09:41:14.040913" level="INFO">wohoo</msg>
<arg>wohoo</arg>
<doc>Logs the given message with the given level.</doc>
<status status="PASS" start="2024-12-06T09:41:14.039912" elapsed="0.002001"/>
</kw>
<status status="PASS" start="2024-12-06T09:41:12.844549" elapsed="1.197364"/>
</test>
<status status="PASS" start="2024-12-06T09:41:12.807856" elapsed="1.238057"/>
</suite>
<status status="PASS" start="2024-12-06T09:41:12.649373" elapsed="1.405075"/>
</suite>
<statistics>
<total>
<stat pass="1" fail="0" skip="0">All Tests</stat>
</total>
<tag>
</tag>
<suite>
<stat pass="1" fail="0" skip="0" id="s1" name="Tmp">Tmp</stat>
<stat pass="1" fail="0" skip="0" id="s1-s1" name="Tests">Tmp.Tests</stat>
</suite>
</statistics>
<errors>
</errors>
</robot>
43 changes: 43 additions & 0 deletions tests/outputs/output_with_latest_robot/third.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<robot generator="Robot 7.0.1 (Python 3.11.1 on darwin)" generated="2024-12-06T09:41:12.426434" rpa="false" schemaversion="5">
<suite id="s1" name="Tmp" source="/Users/mkorpela/workspace/pabot/tmp">
<suite id="s1-s1" name="Tests" source="/Users/mkorpela/workspace/pabot/tmp/tests.robot">
<test id="s1-s1-t1" name="Third" line="14">
<kw name="Log" owner="BuiltIn">
<msg time="2024-12-06T09:41:12.584151" level="INFO">this is third</msg>
<arg>this is third</arg>
<doc>Logs the given message with the given level.</doc>
<status status="PASS" start="2024-12-06T09:41:12.583145" elapsed="0.001006"/>
</kw>
<kw name="Sleep" owner="BuiltIn">
<msg time="2024-12-06T09:41:13.639363" level="INFO">Slept 1 second.</msg>
<arg>1s</arg>
<doc>Pauses the test executed for the given time.</doc>
<status status="PASS" start="2024-12-06T09:41:12.585379" elapsed="1.072033"/>
</kw>
<kw name="Log" owner="BuiltIn">
<msg time="2024-12-06T09:41:13.660512" level="INFO">bruut</msg>
<arg>bruut</arg>
<doc>Logs the given message with the given level.</doc>
<status status="PASS" start="2024-12-06T09:41:13.659485" elapsed="0.002028"/>
</kw>
<status status="PASS" start="2024-12-06T09:41:12.579960" elapsed="1.081553"/>
</test>
<status status="PASS" start="2024-12-06T09:41:12.572945" elapsed="1.109641"/>
</suite>
<status status="PASS" start="2024-12-06T09:41:12.481972" elapsed="1.206628"/>
</suite>
<statistics>
<total>
<stat pass="1" fail="0" skip="0">All Tests</stat>
</total>
<tag>
</tag>
<suite>
<stat pass="1" fail="0" skip="0" id="s1" name="Tmp">Tmp</stat>
<stat pass="1" fail="0" skip="0" id="s1-s1" name="Tests">Tmp.Tests</stat>
</suite>
</statistics>
<errors>
</errors>
</robot>
61 changes: 57 additions & 4 deletions tests/test_resultmerger.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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()

0 comments on commit 6ae40b8

Please sign in to comment.