SOLVED
Generally I guess it is not any bug in coding but some errors with pylance or pyright. My code and directory are both correct, the problem is that, IDE(I tried both VS code and Pycharm) can’t find the path or modules. I installed Pylance, which usually has many many bugs and warnings, however, I tried to run any .py, it went well. So I found that adding these 2 lines in settings.json solved the problem
"python.analysis.diagnosticSeverityOverrides": {"reportGeneralTypeIssues":"none"},
"python.linting.pylintArgs": ["--generate-members"],
Imported a resource succeeded with no error but the libraries show path error as it has no such path. The code is below as a part of the project of Robotframework. All other testcases share the same issues.
The code with error is
*** Settings ***
Documentation
Library ../lib/ue/SparkLibrary/common.py
Library ../lib/vam/VAM_8x8 WITH NAME VAM
Variables ../lib/ue/SparkLibrary/params.py
The errors are with 2 libraries above but it is correct with the Variables at the bottom.
The error said
Unresolved library: ../lib/ue/SparkLibrary/common.py.
Error generating libspec:
Importing library 'common' failed: ModuleNotFoundError: No module named 'flexbot'
Consider adding the needed paths to the "robot.pythonpath" setting
and calling the "Robot Framework: Clear caches and restart" action.robotframework
My folder is like
project/
project/flexbot/
project/flexbot/lib
project/flexbot/lib/ue
project/flexbot/lib/ue/SparkLibrary
project/flexbot/lib/ue/SparkLibrary/common.py and params.py
project/flexbot/lib/vam/VAM_8x8.py
project/flexbot/resource/project1.resource(where the error is located in this file as an example)
I tried to check robotframework.setting.json in Visual Studio Code but it still failed. Same problem as importing libraries failed but resource and variables succeed
2
Answers
Adding these in settings.json probably solves most errors and warning by Pylance (or Pyright). Notice this will still have some waring remain but your code could run anyway. If so, it means your code and directory are both correct, it is not the problem of your coding but something with the setting.
If still can't fix, try to ban the use of Pylance and Pyright or any plugins that may contain them
It seems to me that content inside your common.py is having error.
So in above error line it is saying that you don’t have flexbot library installed. So Try to install this library and then run your robot script again.
NOTE- If the python script that you are importing will have any error or it is not executing successfully then it’ll not get imported in your robot script. Just make sure your python script is free from any error.