Skip to content

Keyword metadata #5627

Open

Description

@Lakitna

If the current planning holds, Robot 7.5 will include test metadata. See #4409.

We already have suite metadata.

Does it make sense to complete the list with Keyword metadata?

Why this may be useful

Recently, I've come up with some separate use cases that could benefit from keyword metadata.

1. Concurrency settings

Medusa uses suite metadata to calculate which tests can run in parallel. It's a clever approach that can be stretched. A tool like Medusa could use keyword metadata like a kind of lock.

The concept of locks already exists with keyword calls in PabotLib. It can be used to prevent multiple test processes from doing the same thing at the same time. For example, when writing to a file you want to lock that operation to prevent race conditions that cause corrupted files. This approach would be metadata-based instead of keyword-based. This could look something like:

Update A Data File
    [Arguments]    ${path}    ${new_content}
    [Metadata]    medusa:lock
    # change the file

Or, maybe

Update A Data File
    [Arguments]    ${path}    ${new_content}
    [Medusa]    lock
    # change the file

3. Caching

In CacheLibrary, I now use a keyword to retrieve from cache and another to write to cache. I got a feature request to cache with a listener instead (Lakitna/robotframework-cache#9).

A configuration like this could be made with metadata:

Do Expensive Calculation
    [Arguments]    ${data}
    [Cache]    1 hour
    # do a 10-minute calculation

3. Decorator

While writing this, I keep thinking that these examples are essentially Python's @decorators.

@amazing_decorator
def some_function:
    pass

With keyword metadata, this can be made in Robot like:

Some Keyword
    [Metadata]    amazing_decorator

On the Library-side, this should be implemented in a listener. If the listener encounters their special metadata string (here: amazing_decorator), it can wrap the keyword like a Python decorator does. The library can now, essentially do advanced keyword setup and teardown.

4. Temporary Library config

Keyword metadata could be used to overwrite some library configs if the library supports this.

Wait For Super Long And Annoying Animation
    [Selenium:timeout]    10 minutes

This would require explicit support from the libraries.

Existing alternatives

To make something like this now, you'd have to use tags, magic docstrings, stick with keywords, or use [Setup] and [Teardown].

Magic tags

Do Expensive Calculation
    [Arguments]    ${data}
    [Tags]    cache:3600
    # do a 10-minute calculation

Magic docstrings

Do Expensive Calculation
    [Documentation]    Lorum ipsum dolor sit amet
    ...  *CACHE:3600*
    [Arguments]    ${data}
    # do a 10-minute calculation

Keywords

Do Expensive Calculation
    [Arguments]    ${data}
    ${cached} =    Cache Retrieve value    amazing_key
    IF    $cached is not $None
        RETURN    ${cached}
    END

    # do a 10-minute calculation

    Cache Store Value    amazing_key    ${outcome}
    RETURN    ${outcome}

Setup and Teardown settings

Update A Data File
    [Arguments]    ${data}
    [Setup]    Cache Retrieve value
    # do a 10-minute calculation
    [Teardown]    Cache Store value

Non-library uses

I'm not sure if this is useful outside the library uses outlined above. I guess you could use it for documentation purposes, but I don't really see the point in a world where [Documentation] and [Tags] already exist.

Activity

  1. pekkaklarck commented on Mar 25, 2026

    @pekkaklarck
    Member

    If we add test metadata (#4409), for consistency reasons it makes sense to add keyword metadata as well. I consider test metadata more important, though, so let's implement that first and then look at this. Getting both done in RF 7.5 would be great, but doing this later is fine as well.

    Let's also limit this issue to simple [Metadata] syntax that can be used like

    *** Keywords ***
    Example
        [Metadata]    Cache    1 hour
        Log    Hello!

    I'll submit a separate issue about specifying metadata on different levels without the [Metadata] or Metadata setting. In this context it would allow using:

    *** Keywords ***
    Example
        [Cache]    1 hour
        Log    Hello!
  2. added this to the v7.5 milestone on Mar 25, 2026
  3. changed the title [-]Custom keyword settings a.k.a. keyword metadata[/-] [+]Keyword metadata[/+] on Mar 25, 2026
  4. Lakitna commented on Mar 25, 2026

    @Lakitna
    Author

    Sounds like a good way to split it. Once [Metadata] is supported, it may be a good idea to question the use of the second way of specifying entirely. It adds complexity that arguably doesn't always warrant the gains. But that will also depend on how people use it I guess.

    I also agree that test metadata has priority over this one. In that sense, it may make more sense to move this post 7.5? Depending on implementation details of test metadata

  5. pekkaklarck commented on Mar 25, 2026

    @pekkaklarck
    Member

    Let's keep this in RF 7.5 for now. Once test metadata is done, we can see where we are with RF 7.5 and decide what to do with this. Test metadata will also give us a pretty good idea about how big task implementing this will be.

  6. modified the milestones: v7.5, v7.6 on Jun 9, 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

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions