Skip to content

Listeners cannot set timeouts #5350

Description

@Lavinu

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.

Activity

  1. pekkaklarck commented on Mar 3, 2025

    @pekkaklarck
    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.

  2. added this to the v7.3 milestone on Mar 3, 2025
  3. changed the title [-]Can not dynamically set Testcase Timeout by Robot Listener[/-] [+]Listeners cannot set timeouts[/+] on Mar 7, 2025
  4. added theissue type on Mar 7, 2025
  5. pekkaklarck commented on Mar 7, 2025

    @pekkaklarck
    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.
  6. modified the milestones: v7.3, v7.4 on Apr 4, 2025
  7. olesz commented on May 5, 2025

    @olesz
    Contributor

    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.

  8. modified the milestones: v7.4, v7.5 on Jun 25, 2025
  9. modified the milestones: v7.5, v7.6 on Jul 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions