Environment variables not used in RF-LS in vscode

Set an environment variable MY_VARIABLE to be used by RF-LS.
Then create a robot script:

*** Settings ***
Library    OperatingSystem


*** Test Cases ***
Show env var
    Environment Variable Should Be Set      MY_VARIABLE

Then run it, and it fails, claiming the variable is not set.

I set the variable by going to Extensions → Robot Framework Language Server → (small gear icon) → Settings. Then in the search write “Env” and click “Edit in settings.js”.
Then add this snippet:

    "robot.python.env": {
        "MY_VARIABLE": "is set for sure"
    },
1 Like

@kamichal I suggest using the RobotCode extension and make use of a robot.toml file or a .robot.toml file (if you don’t want to commit this file to your repository) to store your environment variables.

Example of the content of the toml file

[env]
MY_VARIABLE=“is set for sure”

Just place this file in the root of your project folder, just like you would with a .env file
Also I suggest installing the Even Better TOML extension, for working with TOML files.

1 Like