Assigning values to ${False} or ${True}

Hello,

While upgrading from Robot Framework 4.1.3 to 6.1.1 and adapting our team’s test data I noticed that handling of boolean variables ${False} and ${True} has changed.

A simplified robot test illustrating the problem:

*** Variables ***
${True}    true
${False}    false

*** Test Cases ***
Silly test with boolean variables
    Run Keyword If    ${True}    Log    foo
    Run Keyword If    ${False}    Log    bar

This test passes in version 4.1.3 and logs ‘foo’ as expected but it fails in 6.1.1 with the following error:

Evaluating expression ‘true’ failed: NameError: name ‘true’ is not defined nor importable as module

After running some tests I found that Robot Framework 4.1.3 silently ignores assignments to these variables. In versions 5.0 or newer the assignments are effective and lead to string values being stored in boolean “constants”.

IMO such assignments should raise either syntax error or a warning so that users can easily find root cause for such failures.

What do you think? Should this be raised as a bug/improvement in the issue tracker?

Hi Zoltán,

I just checked in RF 7.0 and got the same error, so it would seem the that the boolean values are getting overwritten by strings as you suggest.

Probably could be raised as an issue, perhaps RF should check for builtin variables being overwritten in the variables section before starting tests?

Maybe raise the issue requesting a better error message? Though I suspect this error might be coming directly from python just based on it’s wording so it might not be an easy fix.

Dave.

I might be mistaken, but I thought that ${True} and ${False} were reserved variable names (representing Boolean True and False respectively). Reference in User’s guide. If you’re overloading them as per your example, seems like you’re asking for trouble.

Q: Do you actually need to use ${True} and ${False} as indicated, or are you actually using other variable names? Regardless, if you want to set a variable to Boolean True or False, then use the example given: ${True} and ${False} respectively.

When you to to compare it, if you represent the variable like $my_var then :robot: resolves it to its actual data type (and therefore Boolean in this case).

Hi Greg,

Agreed, that’s why I suggested a better error message might be the solution, perhaps RF should warn/fail when people overload reserved variables.

Dave.

1 Like