robotframework-tidy
robotframework-tidy copied to clipboard
[Transformer] Shorten setting of test/suite/global variables
If name and values are same they could be shorten like this:
${testVar} Set Variable testVarValue
Set Test Variable ${testVar} ${testVar}
to:
Set Test Variable ${testVar}
${suiteVar} Set Variable suiteVarValue
Set Suite Variable ${suiteVar} ${suiteVar}
to:
Set Suite Variable ${suiteVar}
${globalVar} Set Variable globalVarValue
Set Global Variable ${globalVar} ${globalVar}
to:
Set Global Variable ${globalVar}
I guess there are errors in the proposed statements: these should be
Set Test Variable ${testVar} testVarValue
and so on...
Based on https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Set%20Suite%20Variable
I'd think that
${suiteVar} Some Keyword someParam
Set Suite Variable ${suiteVar} ${suiteVar}
would be formatted as:
${suiteVar} Some Keyword someParam
Set Suite Variable ${suiteVar}
(where Some Keyword
could be Set Variable
, or pretty much any keyword that returns a value)
I guess there are errors in the proposed statements: these should be
Set Test Variable ${testVar} testVarValue
and so on...
In case we have simple
${testVar} Set Variable testVarValue
Set Test Variable ${testVar} ${testVar}
it would be possible to do
Set Test Variable ${testVar} testVarValue
but that's not the goal of the author of the issue. Set X Variable are usually used to change scope of the variable - you can set new variable (Set Test Variable ${testVar} testVarValue
) or "rescope" local variable (Set Test Variable ${testVar} ${testVar}
). The other case is what this issue is about - to create Set Test Variable ${testVar}
instead so it's easy to see we're just "rescoping".
This should be easy to implement so I will take a look into it soon.