Skip to content

Variables should not leak to lower level keywords #532

Closed

Description

@spooning

Originally submitted to Google Code by @pekkaklarck on 14 Apr 2010

Currently this is passes:

*** Test Case ***
Example
    ${x}=    Set Variable    hello
    My keyword

*** Keywords ***
My keyword
    Should be equal    ${x}    hello
    ${y}=    Set Variable    world
    Second keyword

Second Keyword
    Should be equal    ${x}    hello
    Should be equal    ${y}    world

This has definitely been a bad design decision, and a person who
has designed it years ago I can call it a bug rather than a feature.
Instead of variables leaking to lower level keywords like this, they should
be passed as argument or, in special cases, set explicitly using Set Test
Variable keyword.

Even though this is a misfeature, we cannot remove it without deprecating
first it because existing tests may depend on it. Unfortunately the current
variable implementation is so naïve that deprecation cannot be easily done
without larger changes that don't fit into RF 2.5 scope. We thus probably
need to deprecate this in 2.6 and remove fully in 2.7.


EDIT: Deprecation wasn't easy in RF 2.9 where this bug finally was fixed and we decided not to do it. We can reconsider that if there are lot of complaints during the preview releases.

Activity

  1. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor
  2. added this to the 2.9 milestone on Jun 29, 2014
  3. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by cmalu... on 16 Apr 2010

    Maybe, It will be useful if you can run Robot with a parameter for avoid the
    "Variable leaking" for a while.
    Something like: pybot -l test

  4. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @pekkaklarck on 16 Apr 2010

    I think a good plan how to resolve variables in RF 2.6 is this:

    1. Don't put variables inside a test or keyword into the scope of the lower level
      keyword.
    2. Don't put variables in test, suite, or global level there either.
    3. When resolving variables, first look the local scope.
    4. If there is no variable in the local scope, look the scopes of the higher level
      keywords and test.
    5. If var is found from higher level scopes, use it but show a deprecation warning.
    6. If var still not found, look for it from test, suite, and global scopes in that order.
    7. If no var found, resolving failed.

    In RF 2.7 we can then skip steps 4) and 5) altogether.

  5. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @pekkaklarck on 28 Jun 2010

    Issue 579 has been merged into this issue.

  6. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @spooning on 2 Dec 2011

    Initially descoped from 2.7 due to lack of time

  7. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by kormbrek on 19 Nov 2012

    This can lead to strange behavior if the lower keyword relies on "Using list variables as scalar variables" functionality.
    For example:
    If higher level keyword defines local ${items}, lower level keyword defines local @⁠{items}, and then lower level keyword tries to use the list as a scaler - ${items}, it has the value set in the higher keyword and the value is not related to @⁠{items}.

  8. edbrannin commented on Feb 27, 2015

    @edbrannin
    Contributor

    Thankfully, the previous comment's concern should be moot after #1905 is complete.

  9. self-assigned this
    on Jun 11, 2015
  10. pekkaklarck commented on Jun 14, 2015

    @pekkaklarck
    Member

    5ce6db7 implemented this and handling variable scopes was cleaned up in 87f0ce1 and 0078f2f. Still need to look what User Guide says about variable scopes but otherwise this issue ought to be done.

  11. pekkaklarck commented on Jun 15, 2015

    @pekkaklarck
    Member

    Enhanced documentation in 2c1917b. Could you @jussimalinen review and close this issue when done?

    Also noticed that the original description said we cannot change the behavior without a deprecation period. Deprecation would have been so much work that our plan is to "just do it". We can still reconsider this if there are enough complaints during preview releases.

  12. jussimalinen commented on Jun 15, 2015

    @jussimalinen
    Member

    Looks good. Lets hope this wont break too much old tests...

  13. added theissue type on Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions