DEPR05 Set Suite Variable used instead of VAR is a fool

Hi fellow robots,

I’m seeking guidance regarding a recommendation from Robocop (the Robot Framework linter) and the limitations I’m encountering when trying to adhere to modern variable assignment practices.

Robocop frequently raises the DEPR05 warning - documenation:

DEPR05 Set Suite Variable used instead of VAR

This correctly identifies that the deprecated after robot 7.0 Set Suite Variable (or Set Global Variable) are discouraged in favor of the newer, more concise VAR syntax.

The warning in Builtin library:

NOTE: It is recommended to use the VAR syntax introduced in Robot Framework 7.0 for creating variables in different scopes instead of the Set Global/Suite/Test/Local Variable keywords. It makes creating variables uniform and avoids all the problems discussed above.

However, I rely on setting variables dynamically within a Suite Setup that need to be accessed by subsequent test cases in the suite.

For example,

When I attempt to follow Robocop’s recommendation and use the VAR syntax:

*** Test Cases ***
Create Title
    VAR    ${TITLE_CAPTION}=    Generate Readable Username  # this robocop recommended to use
...

Search Title
    Search    ${TITLE_CAPTION} # Fails: Variable '${TITLE_CAPTION}' not found.

The variable ${TITLE_CAPTION}, when defined using VAR, is strictly test-local in scope and is destroyed after the first test case finishes.

Therefore, for dynamic variables that must persist across an entire suite or globally, I am forced to fall back to the “deprecated” approach:

Code snippet

*** Test Cases ***
Create Title
    ${token}=    Advertiser.Prepare Advertiser Test Context
    Set Suite Variable    ${AUDIENCE_TOKEN}    ${token}  # This works, but triggers DEPR05 (VAR linter)


My questions:

  • Is there a modern, Robocop-compliant syntax (like VAR) that allows explicit control over the scope (e.g., Suite or Global)?

  • If not, should the Robocop rule DEPR05 be softened or retired for cases where dynamic assignment of Suite/Global variables is necessary, acknowledging that Set Suite Variable is currently the only non-Python method available?

When using the `VAR` syntax, you can specify the scope of the variable. See here:

For instance:

*** Test Cases ***
Scope example
VAR ${local} local value
VAR ${TEST} test value scope=TEST
VAR ${SUITE} suite value scope=SUITE
VAR ${SUITES} nested suite value scope=SUITES
VAR ${GLOBAL} global value scope=GLOBAL

5 Likes

As already mentioned, you need to use VAR with scope=SUITE to assign variables in suite level. Notice also that Suite Setup itself needs to be a keyword, so something like

*** Settings ***
Suite Setup       VAR    ${EXAMPLE}    value    scope=SUITE

doesn’t work. There’s no problem if you the keyword used as a suite setup uses the VAR syntax, though.