Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Listeners cannot set timeouts #5350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Lavinu opened this issue Mar 3, 2025 · 3 comments
Open

Listeners cannot set timeouts #5350

Lavinu opened this issue Mar 3, 2025 · 3 comments

Comments

@Lavinu
Copy link

Lavinu commented Mar 3, 2025

Description:
I want to use a Robot Framework listener to dynamically set the execution time for each test case during test execution. For example, in a CI scenario, I can define a total execution time, and during the Robot Framework run, dynamically adjust the remaining execution time for each test case.

However, it seems that there is currently no way to modify a test case's timeout parameter through a listener:

from robot import result, running
from testlogging import debug_log
logger = debug_log(__file__)

class TimeoutConfig:

    ROBOT_LISTENER_API_VERSION = 3

    def __init__(self, timeout: str):
        self.timeout = timeout
    def start_test(self, data: running.TestCase, result: result.TestSuite):
        logger.info('ROBOT LISTENER: Test Case {} has timeout {}', data.name, data.timeout)
        data.timeout = self.timeout
        logger.info('ROBOT LISTENER: Test Case {} has timeout {}', data.name, data.timeout)

Test case:

Suite Teardown      Suite Teardown

*** Test Cases ***
Log Hello World
    [Timeout]    5
    [Teardown]    Testcase Teardown
    Sleep    20

The console shows data.timout output was modified but the robot report shows the timeout still keep original.

@pekkaklarck
Copy link
Member

I believe Robot checks the timeout before calling listeners. In that case it ought to be enough to change the order. We've been enhancing listeners heavily in the RF 7.x series and should fix this limitation as well.

I think the result object has the timeout as a custom object that's not even properly documented. This part may require changes as well.

@pekkaklarck pekkaklarck added this to the v7.3 milestone Mar 3, 2025
@pekkaklarck pekkaklarck changed the title Can not dynamically set Testcase Timeout by Robot Listener Listeners cannot set timeouts Mar 7, 2025
@pekkaklarck
Copy link
Member

I looked at this quickly and some quick comments based on that:

  • Fixing the problem isn't as simple as I thought. The main reason is that timeout handling is internally implemented somewhat stupidly and it might be best to cleanup that as part of this issue.
  • Related to the, I believe timeouts should be represented as timedelta objects, but changing that should possibly wait for a major release where backwards incompatible changes are less problematic.
  • We also need to check how keyword timeouts work.

@pekkaklarck pekkaklarck modified the milestones: v7.3, v7.4 Apr 4, 2025
@olesz
Copy link
Contributor

olesz commented May 5, 2025

I encountered the same issue and for me the following workaround worked to set the timeout to two seconds:

def start_test(self, data: running.TestSuite, result: result.TestSuite) -> None:
   data.timeout = "2"
   result.timeout.string = str(2)
   result.timeout.secs = float(2)

Note: this works if there is an already existing timeout set on the test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants