I was revisiting this and decided to post a full working example incase it helps someone else.
BTW Thanks @pekkaklarck for all your help with this.
Run Command:
robot --listener TestRepeater.py repeatme.robot
TestRepeater.py
from robot.api import SuiteVisitor
import time
class TestRepeater(SuiteVisitor):
ROBOT_LISTENER_API_VERSION = 3
testname = None
count = 1
def end_test(self, test, result):
# print("test:", test)
# print("test.parent:", test.parent)
# print("test.parent.tests:", test.parent.tests)
if self.count < 5:
self.count += 1
if self.testname is None:
self.testname = test.name
newname = "{} {}".format(self.testname, self.count)
copy = test.copy(name=newname)
test.parent.tests.append(copy)
# test.parent.tests.append(test)
def end_suite(self, suite, result):
# This prevents the error:
# [ ERROR ] Calling method 'end_suite' of listener 'TestRepeater.py' failed: TypeError: end_suite() takes 2 positional arguments but 3 were given
pass
def start_suite(self, suite, result):
# This prevents the error:
# [ ERROR ] Calling method 'start_suite' of listener 'TestRepeater.py' failed: TypeError: start_suite() takes 2 positional arguments but 3 were given
pass
def start_test(self, test, result):
# This prevents the error:
# [ ERROR ] Calling method 'start_test' of listener 'TestRepeater.py' failed: TypeError: start_test() takes 2 positional arguments but 3 were given
pass
repeatme.robot
*** Settings ***
Suite Setup SS keyword
Suite Teardown ST keyword
Test Setup TS keyword
Test Teardown TT keyword
*** Test Cases ***
Repeat Me
${time} = Get Time
Log Repeat Me ${time}
Log To Console Repeat Me ${time}
Sleep 5
*** Keywords ***
SS keyword
Log Suite Setup
Log To Console Suite Setup
TS keyword
Log Test Setup
Log To Console Test Setup
ST keyword
Log Suite Teardown
Log To Console Suite Teardown
TT keyword
Log Test Teardown
Log To Console Test Teardown
Result
==============================================================================
Repeatme
==============================================================================
Suite Setup
Repeat Me Test Setup
...Repeat Me 2023-03-06 11:36:24
..Test Teardown
Repeat Me | PASS |
------------------------------------------------------------------------------
Repeat Me 2 Test Setup
...Repeat Me 2023-03-06 11:36:29
..Test Teardown
Repeat Me 2 | PASS |
------------------------------------------------------------------------------
Repeat Me 3 Test Setup
...Repeat Me 2023-03-06 11:36:34
..Test Teardown
Repeat Me 3 | PASS |
------------------------------------------------------------------------------
Repeat Me 4 Test Setup
...Repeat Me 2023-03-06 11:36:39
..Test Teardown
Repeat Me 4 | PASS |
------------------------------------------------------------------------------
Repeat Me 5 Test Setup
...Repeat Me 2023-03-06 11:36:44
..Test Teardown
Repeat Me 5 | PASS |
------------------------------------------------------------------------------
Suite Teardown
Repeatme | PASS |
5 tests, 5 passed, 0 failed
==============================================================================
Output: /Users/dave/tmp/RepeatTest/output.xml
Log: /Users/dave/tmp/RepeatTest/log.html
Report: /Users/dave/tmp/RepeatTest/report.html