marquillo
marquillo

Reputation: 87

Variable is created even if condition is not true in robot framework

In my keyword I got a for loop, in which I append items into the list. At some point I would like to empty this list, so I can start appending items again.

Append to List    ${list}    ${data}
@{list}=  Run Keyword If  ${list_length} == 10 or ${cond} == 1    my_keyword    ${arg1}
        ...         ${arg2}

my_keyword    ${arg1}    ${arg2}
   Do some stuff
   @{list}    Create List
   Return     ${list}

New empty list is created for every iteration, not only when condition is met, the other stuff from my_keyword is executed only when condition is met. What should I change to create new list only if condition is met?

Upvotes: 0

Views: 565

Answers (1)

soyacz
soyacz

Reputation: 457

Having @{list}= before Run Keyword If will assign value to it regardless if executed keyword or not. So in case condition is not met, it will assign None to @{list}. If you want to keep current list, then add 'ELSE' part:

@{list}=  Run Keyword If  ${list_length} == 10 or ${cond} == 1    my_keyword    ${arg1}
    ...         ${arg2}    ELSE    set variable    ${list}

Upvotes: 2

Related Questions