Required VSCode env variables for RoboCorp

Hello Guys,

I’m trying to migrate an existing API testing project from PyTest to Robot Framework but I find hard to import some of the custom python libraries due to the following error:

Unresolved library: general.py.
Error generating libspec:
Importing library 'general' failed: ImportError: attempted relative import with no known parent package
Consider adding the needed paths to the "robot.pythonpath" setting
and calling the "Robot Framework: Clear caches and restart"   robotframework

Python libraries which return that error try to import other libraries two levels above them. Let me show similar hierarchy:

project/
    β”œβ”€β”€ src/
    β”‚   β”œβ”€β”€ __init__.py
    β”‚   β”œβ”€β”€ folder1/
    β”‚   β”‚   β”œβ”€β”€ __init__.py
    β”‚   β”‚   β”œβ”€β”€ test_cases.robot
    β”‚   β”‚   β”œβ”€β”€ keywords.resource
    β”‚   β”‚   β”œβ”€β”€ general.py
    β”‚   β”‚   β”œβ”€β”€ sample.py
    β”‚   β”œβ”€β”€ folder2/
    β”‚   β”‚   β”œβ”€β”€ __init__.py
    β”‚   β”‚   β”œβ”€β”€ file3.py
    β”‚   β”‚   β”œβ”€β”€ file4.py
    β”‚   β”œβ”€β”€ folder3/
    β”‚   β”‚   β”œβ”€β”€ __init__.py
    β”‚   β”‚   β”œβ”€β”€ file5.py
    β”‚   β”œβ”€β”€ folder4/
    β”‚   β”‚   β”œβ”€β”€ __init__.py
    β”‚   β”‚   β”œβ”€β”€ file6.py
    β”‚   β”‚   β”œβ”€β”€ file7.py
    β”‚   β”œβ”€β”€ folder5/
    β”‚   β”‚   β”œβ”€β”€ __init__.py
    β”‚   β”‚   β”œβ”€β”€ file8.py
    β”‚   β”‚   β”œβ”€β”€ file9.py
    β”œβ”€β”€ .vscode/
    β”‚   β”œβ”€β”€ settings.json
    β”œβ”€β”€ venv/

So for example, in keywords.resource file I try to import general.py with β€œLibrary general.py” under Settings section and that general.py has imports from folder2 and folder3, e.g. β€œfrom …folder2.file3 import get_action, post_action”.

I’m working in a virtual environment called β€œvenv” which return the absolute path of the project if I echo the $PYTHONPATH variable:

% echo $PYTHONPATH
/path/to/project/

In my .vscode/settings.json in the project I have paths to the project and sub-folder:

{
    "robot.pythonpath": [
        "${workspaceFolder}/",
        "${workspaceFolder}/src",
        "${workspaceFolder}/src/folder2"
    ]
}

If I try to import a module within the same folder scrope with no imports inside it - no error is returned by robotframework.

So obviously I’m missing something very fundamental.
Thanks in advance for the help!

I would highly recommend to look thru our documentation to get started, see:

1 Like