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.
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:
Or, maybe
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:
3. Decorator
While writing this, I keep thinking that these examples are essentially Python's
@decorators.With keyword metadata, this can be made in Robot like:
Some Keyword [Metadata] amazing_decoratorOn 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 minutesThis 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
Magic docstrings
Keywords
Setup and Teardown settings
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.