Reputation: 672
In the Robot Framework user guide, it states a variable value is a list or list-like, it is also possible to use it as a list variable like @{EXAMPLE}
and There is also an empty list variable @{EMPTY}
but I am not able to create an empty list. In the minimally reproducible example below, no matter how I set it up I get the error, TypeError: Expected argument 1 to be a list or list-like, got string instead
in my test case. How can I create an empty list that doesn't re-assign itself to be a string?
*** Settings ***
Library Collections
Suite Setup Re-instantiate List
*** Variables ***
@{shouldBeList}= @{EMPTY}
*** Test Cases ***
Add something to the list
Collections.Append to list @{shouldBeList} Test
*** Keywords ***
Re-instantiate List
@{shouldBeList}= Create List ${EMPTY}
Set Suite Variable @{shouldBeList} @{shouldBeList}
# Results:
# Add something to the list | FAIL |
# TypeError: Expected argument 1 to be a list or list-like, got string instead.
Upvotes: 1
Views: 4257
Reputation: 672
I should have read the user guide more closely.
All variables should be assigned using the ${var}
syntax, including lists and dicts. The @{var}
and &{var}
syntax should be used when you want to unpack the ${var}
, using the @ symbol if it's list-like and & if it's dict-like.
My above code works when written as:
*** Settings ***
Library Collections
Suite Setup Re-instantiate List
*** Variables ***
*** Test Cases ***
Add something to the list
Collections.Append to list ${shouldBeList} Test
*** Keywords ***
Re-instantiate List
${shouldBeList}= Create List
Set Suite Variable @{shouldBeList} @{shouldBeList}
Upvotes: 3