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!