Skip to content

[BUG] Arrays created in a Variables file cannot be passed as Library argument  #174

Open
@marques-bruno

Description

@marques-bruno

Hi, I've noticed the following issue while using the extension:

Describe the bug
When instantiating an argument-taking python library in a robot file (Library | CustomLib.py | ${Argument}), if ${Argument} is an array or a mapping, and if this array / mapping was declared in a Variables file (Variables | MyVars.py) the extension will fail to initialize the library.

To Reproduce
Steps to reproduce the behavior:
Create a simple project, with:

  • a variables file Variables.py:
def get_variables():
    variables = {"VARIABLE": "An example string",
                 "ANOTHER_VARIABLE": "This is pretty easy!",
                 "INTEGER": 42,
                 "STRINGS": ["one", "two", "kolme", "four"],
                 "NUMBERS": [1, 42, 3.14],
                 "MAPPING": {"one": 1, "two": 2, "three": 3}}
    return variables
  • a library file CustomLib.py:
from robot.api import logger
from robot.api.deco import keyword

class CustomLib(object):
    ROBOT_LIBRARY_SCOPE = 'SUITE'

    def __init__(self, VARIABLE, ANOTHER_VARIABLE, INTEGER, STRINGS, NUMBERS, MAPPING):
        self.variable = VARIABLE
        self.another_variable = ANOTHER_VARIABLE
        self.integer = INTEGER
        self.strings = STRINGS
        self.numbers = NUMBERS
        self.mapping = MAPPING

    @keyword("Call foo")
    def foo(self):
        logger.info(f"variable: {self.variable}")
        logger.info(f"another variable: {self.another_variable}")
        logger.info(f"integer {self.integer}")
        logger.info(f"strings {self.strings}")
        logger.info(f"numbers {self.numbers}")
        logger.info(f"mapping {self.mapping}")
  • a robot file test.robot:
*** Settings ***
Variables      Variables.py
Library        CustomLib.py    ${VARIABLE}  ${ANOTHER_VARIABLE}  ${INTEGER}  ${STRINGS}  ${NUMBERS}  ${MAPPING}
# Library        CustomLib.py    ${VARIABLE}  ${ANOTHER_VARIABLE}  ${INTEGER}  ${STRINGLIST}  ${NUMBERLIST}  ${DICTIONARY}

*** Variables ***
@{STRINGLIST}    Hello    World
@{NUMBERLIST}    1    2    3
&{DICTIONARY}    one=1  two=2  three=3}

*** Test Cases ***
Test case
    Call foo

Expected behavior
The test Test case will pass successfully, but the extension will produce an error when instantiating the library (Variable '${STRINGS}' not found. robotcode.namespace(VariableError))
Variables created within the robot file will not cause this issue (uncommenting l.4 and commenting l.3 in the robot file will show that the expect behavior works when the variables aren't declared in a dedicated Variables file). Unless of course the variable was constructed out of values coming from non-scalar values in the Variables.py

Screenshots
image

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions