Robot Framework
robot.api.deco Namespace Reference

Functions

def keyword (name=None, tags=(), types=())
 Decorator to set custom name, tags and argument types to keywords. More...
 
def library (scope=None, version=None, converters=None, doc_format=None, listener=None, auto_keywords=False)
 Class decorator to control keyword discovery and other library settings. More...
 
def not_keyword (func)
 Decorator to disable exposing functions or methods as keywords. More...
 

Variables

 ROBOT_AUTO_KEYWORDS
 
 ROBOT_LIBRARY_CONVERTERS
 
 ROBOT_LIBRARY_DOC_FORMAT
 
 ROBOT_LIBRARY_LISTENER
 
 ROBOT_LIBRARY_SCOPE
 
 ROBOT_LIBRARY_VERSION
 

Function Documentation

◆ keyword()

def robot.api.deco.keyword (   name = None,
  tags = (),
  types = () 
)

Decorator to set custom name, tags and argument types to keywords.

This decorator creates ``robot_name``, ``robot_tags`` and ``robot_types``
attributes on the decorated keyword function or method based on the
provided arguments. Robot Framework checks them to determine the keyword's
name, tags, and argument types, respectively.

Name must be given as a string, tags as a list of strings, and types
either as a dictionary mapping argument names to types or as a list
of types mapped to arguments based on position. It is OK to specify types
only to some arguments, and setting ``types`` to ``None`` disables type
conversion altogether.

If the automatic keyword discovery has been disabled with the
:func:`library` decorator or by setting the ``ROBOT_AUTO_KEYWORDS``
attribute to a false value, this decorator is needed to mark functions
or methods keywords.

Examples::

    @keyword
    def example():
        # ...

    @keyword('Login as user "${user}" with password "${password}"',
             tags=['custom name', 'embedded arguments', 'tags'])
    def login(user, password):
        # ...

    @keyword(types={'length': int, 'case_insensitive': bool})
    def types_as_dict(length, case_insensitive):
        # ...

    @keyword(types=[int, bool])
    def types_as_list(length, case_insensitive):
        # ...

    @keyword(types=None])
    def no_conversion(length, case_insensitive=False):
        # ...

Definition at line 86 of file deco.py.

◆ library()

def robot.api.deco.library (   scope = None,
  version = None,
  converters = None,
  doc_format = None,
  listener = None,
  auto_keywords = False 
)

Class decorator to control keyword discovery and other library settings.

By default disables automatic keyword detection by setting class attribute
``ROBOT_AUTO_KEYWORDS = False`` to the decorated library. In that mode
only methods decorated explicitly with the :func:`keyword` decorator become
keywords. If that is not desired, automatic keyword discovery can be
enabled by using ``auto_keywords=True``.

Arguments ``scope``, ``version``, ``converters``, ``doc_format`` and ``listener``
set library's scope, version, converters, documentation format and listener by
using class attributes ``ROBOT_LIBRARY_SCOPE``, ``ROBOT_LIBRARY_VERSION``,
``ROBOT_LIBRARY_CONVERTERS``, ``ROBOT_LIBRARY_DOC_FORMAT`` and
``ROBOT_LIBRARY_LISTENER``, respectively. These attributes are only set if
the related arguments are given and they override possible existing attributes
in the decorated class.

Examples::

    @library
    class KeywordDiscovery:

        @keyword
        def do_something(self):
            # ...

        def not_keyword(self):
            # ...


    @library(scope='GLOBAL', version='3.2')
    class LibraryConfiguration:
        # ...

The ``@library`` decorator is new in Robot Framework 3.2.
The ``converters`` argument is new in Robot Framework 5.0.

Definition at line 136 of file deco.py.

◆ not_keyword()

def robot.api.deco.not_keyword (   func)

Decorator to disable exposing functions or methods as keywords.

Examples::

    @not_keyword
    def not_exposed_as_keyword():
        # ...

    def exposed_as_keyword():
        # ...

Alternatively the automatic keyword discovery can be disabled with
the :func:`library` decorator or by setting the ``ROBOT_AUTO_KEYWORDS``
attribute to a false value.

New in Robot Framework 3.2.

Definition at line 36 of file deco.py.

Variable Documentation

◆ ROBOT_AUTO_KEYWORDS

robot.api.deco.ROBOT_AUTO_KEYWORDS

Definition at line 152 of file deco.py.

◆ ROBOT_LIBRARY_CONVERTERS

robot.api.deco.ROBOT_LIBRARY_CONVERTERS

Definition at line 147 of file deco.py.

◆ ROBOT_LIBRARY_DOC_FORMAT

robot.api.deco.ROBOT_LIBRARY_DOC_FORMAT

Definition at line 149 of file deco.py.

◆ ROBOT_LIBRARY_LISTENER

robot.api.deco.ROBOT_LIBRARY_LISTENER

Definition at line 151 of file deco.py.

◆ ROBOT_LIBRARY_SCOPE

robot.api.deco.ROBOT_LIBRARY_SCOPE

Definition at line 143 of file deco.py.

◆ ROBOT_LIBRARY_VERSION

robot.api.deco.ROBOT_LIBRARY_VERSION

Definition at line 145 of file deco.py.