| Issue 280: | It is not possible to set test/suite/global variable using an empty list variable as a value | |
| 1 person starred this issue and may be notified of changes. | Back to list |
Sign in to add a comment
|
Using Robot Framework 2.0.4 (Python 2.6 on linux2)
We have a global variable @{gl}. Let's assume, that this variable already
has some contents, for example [ This | is | a | list ]. Now we have some
user keyword, which returns a list (but for demonstration, we can as well
use the builtin "Create List"). We want to assign the result of the
keyword to the global variable, hence we have to set a local list variable
first. If the local variable is an empty list, then "Set Global Variable"
has no effect. See good example:
| Set Global Variable | \@{gl} | This | is | a | list |
| @{l}= | Create List | Short|List| | |
| Set Global Variable | \@{gl} | @{l} | | | |
Okay, @{gl} is set to the contents of @{l}.
Bad example:
| Set Global Variable | \@{gl} | This | is | a | list |
| @{l}= | Create List | | | | |
| Set Global Variable | \@{gl} | @{l} | | | |
FAULT: @{gl} remains unchanged ! "Set Global Variable" keyword apparently
interprets the empy list @{l} as "less than nothing", which means it
doesn't do anything!
If we set @{l} to ${EMPTY}, the @{gl} is changed, but the @{l} and
afterwards @{gl} is not an empty list, but a list containing one empty
element, which is a difference (for example to the "Log Many" keyword).
Another strange thing: "Set Variable" keyword can assign lists, but raises
an error in case of an empty list. Example:
| @{l}= | Set Variable | | |
results in error "Cannot assign return value of keyword 'BuiltIn.Set
Variable' to variable '@{l}': Expected list, got string instead", which is
quite nonsense. In particular, if the empty list to assign is another
variable, for example:
| @{empty_list}= | Create List | | |
| @{l}= | Set Variable | @{empty_list} | |
Imagine in the above example, that instead "Create List" we have a user
keyword, which may return an empty or non-empty list, depending on time of
day, for instance.
|
||||||||||||
,
Apr 08, 2009
All these problems are due to empty list variables being handled in the test data so
that they are pretty much ignored. That is why
| @{l}= | Create List | |
| Set Global Variable | \@{gl} | @{l} |
is identical to
| Set Global Variable | \@{gl} | |
which means that @{gl} variable should be set in the global scope to the value @{gl}
currently has. If you would change @{gl} in these examples to @{non existing} the
test would fail.
Just two days ago Juha and I looked at the code of Set Test/Suite/Global Variable
keywords when we changed them to accept normal variables as variable names to set
( issue 278 ). This change meant that these keywords get all the values in the test
data as-is without variables being replaced (i.e. they see @{var} even if it would be
empty). We actually happened to discuss what to do in that situation and thought this
is such a corner case that it is better to keep the old behavior. Apparently our
users are finding also all these corners so I changed the logic in r1759 and
| @{l}= | Create List | |
| Set Global Variable | @{gl} | @{l} |
will actuall set @{gl} to an empty list in RF 2.1 final.
In the second case you should use Crate List when assigning @{empty_list} to a new
variable instead of Set Variable. Set Variable is meant to be used to set only scalar
variable, and using it with any other than exactly one value has already been
deprecated in RF 2.1 ( issue 262 ).
Summary: It is not possible to set test/suite/global variable using an empty list variable as a value
Status: Done Owner: pekka.klarck Labels: -Priority-Medium Priority-Low Target-2.1 |
|||||||||||||
|
|
|||||||||||||