Global Scripts added but error No module named
-
When run test script at Squish IDE, the application does not launch and error returned:
Detail ModuleNotFoundError: No module named 'prj_lib' C:\AutotestProject\testscripts\suite_1\tst_case_default\test.py:3I have added the C:\prj_lib as Global Scripts, but still error occured.
in the test.py
from prj_lib import * call function from mod1.py
The project structure:
all test scripts under:
C:\AutotestProject\testscripts\suite_1the custom python scripts to be called in test script by using from prj_lib import *
C:\prj_lib\app -
@Qttest123
Hello,from x import *
This type of import should only be used in a python console session and never in a script as you will pollute your local namespace.
Only import the symbols you need with
from x import y
or use the symbol from the module
import x x.y
If you add the folder itself to the global scripts this would be the same as adding the folder to the Python Searchpath.
You need to add the parent folder to have the folder be recognized as a module.
I would recommend moving your module in another folder and not add the C: drive to the global scripts. -
@LarsS said in Global Scripts added but error No module named:
python console session
i am not sure what is " python console session "
I guess the originator wanted to run the squish from command when triggered by Jenkins?what is the solution to support both, run console also run from squish ide?
also I am not sure what is Python Searchpath.
what is parent folder? and where to add it? in the squish IDE?
and i dont quite sure what do you mean by moving 'module' in another folder....
sorry i am completely new to squish, please let me know what is the best practise. -
Hi @Qttest123
You surely already saw this but we never know ^^ :
https://doc.qt.io/squish/global-scripts-view.html#ide-the-global-scripts-view
and this directly made by Froglogic team:
https://www.youtube.com/watch?v=7aE_OkpJSNYThe python console session is a command line window where you can script and execute live Python (ex : Cmd).
The Python SearchPath is where all Python's lib are installed.
A module is a "library". When you do "import toto" toto is a module. So here last comment is right you should put your external lib in "C:\AutotestProject\shared_lib" for exemple. It's in the section of "best practice" if you want.
In this exemple "C:\AutotestProject\shared_lib", the folder "shared_lib" will be the parent folder of all you .py lib in it.
It seems that you are new to Python too. You can also check how to call an external python class to improve your knowledge. Just a simple example will help you.
https://www.geeksforgeeks.org/python-call-function-from-another-file/I hope it will help you.
-
@SylvainA I updated my project structure:
all test scripts under:
G:\test\automated_test\AutotestProject3\testscriptsthe custom python scripts to be called in test script by using "from project_lib import *"
G:\test\automated_test\AutotestProject3\project_libthen you commented : So here last comment is right you should put your external lib in "C:\AutotestProject\shared_lib" for example.
is the "shared_lib" a fixed name and directory that I should use in order to let squish automatically recognize where is the external libraries?
then what is the usage of "Global Scripts" ? the originator seems thought that it can be used to point the external libraries but in my case it does not work.
I did not see such problem when using open source test framework and pycharm to point them.
I guess Squish has special way to do it?