[Python] VSCode debug always sets cwd to test file's folder in Robot Framework project —...

Discussão em 'Python' iniciado por Stack, Junho 27, 2025.

  1. Stack

    Stack Membro Participativo

    Context


    I'm working on a Robot Framework project using VSCode and the robotcode extension (robotcode-dbiel). In production, we have one git repo for the framework, and one git repo for any test related assets maintained separately.

    Therefore when developing / debugging my folder structure looks like this:

    git/
    ├── .vscode/
    │ └── launch.json
    ├── FW/
    │ └── Python libraries, resource files
    ├── FW-TEST-RESOURCES/
    │ └── test_cases
    │ └── input_variables.yaml <--- Paths of configuration files relative to working dir folder which will be loaded in the various python scripts


    When I CD to git, and run robot via CLI it works.

    robot FW-TEST-RESOURCES/test_cases/test.robot


    But when I set up my launch.json for debugging,

    {
    "name": "Robotcode: Run Test with Root CWD",
    "type": "robotcode",
    "request": "launch",
    "target": "${file}", // Runs the currently active file
    "cwd": "${workspaceFolder}", // Forces CWD to the root (your git folder)
    "args": [],
    }

    Problem


    Even though I’ve explicitly set "cwd": "${workspaceFolder}", the debugger still sets the current working directory to the base folder of the git repo of the test file (e.g., FW-TEST-RESOURCES/), not the root git/ folder.

    This breaks my logic because:


    • I load input_variables.yaml (stored in FW-TEST-RESOURCES/), which contains relative paths from the git folder pointing at paths inside FW folder.


    • My Python code in FW/ expects to resolve these paths relative to the root project folder (git/), since cwd is wrong, when I prepend Path.cwd() to the relative path, I get errors like:

      FileNotFoundError: Configuration file 'git/FW-TEST-RESOURCES/FW/configs/config.yaml' not found!

      When the expected path would be git/FW/configs/config.yaml

    I have also tried hardcoding the cwd in launch.json to the absolute path of the git folder, with same result.

    How can I make VSCode and robotcode use the actual workspace root (git/) as the working directory during debug runs? So it works as when I run it from CLI with robot

    Continue reading...

Compartilhe esta Página