robotframework-tidy icon indicating copy to clipboard operation
robotframework-tidy copied to clipboard

[Transformer] Shorten setting of test/suite/global variables

Open adrszad opened this issue 3 years ago • 3 comments

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}

adrszad avatar Jun 10 '21 11:06 adrszad

I guess there are errors in the proposed statements: these should be Set Test Variable  ${testVar}  testVarValue and so on...

MoreFamed avatar Apr 21 '22 10:04 MoreFamed

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)

Zeckie avatar May 30 '22 13:05 Zeckie

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.

bhirsz avatar May 31 '22 08:05 bhirsz