I am using TestStand 2019 f2 (184.108.40.206 32 bit), python 3.7 on Windows10.
I am traying to call a tkinter GUI app in python with operation type Call Method.
I get the following:
list index out of rangeCall Stack information:
File "c:\users\?\teststand\test-stand-base\teststand\python code modules\monitor\source\monitor.py", line 80, in test_stand_entry
root = tk.Tk()
File "C:\Users\?\AppData\Local\Programs\Python\Python37-32\Lib\tkinter\__init__.py", line 2018, in __init__
baseName = os.path.basename(sys.argv)IndexError: list index out of range
The sys.argv should be the script file full path, and is not set by testStand for some reason. My Adapter settings are:
Python Interpreter: Global, without any virtual env.
Did you find an answer for this? I have the exact same issue.
I call a python action step. have a simple hello world function that I call where I also print out the sys.argv but the list is empty where I'm expecting the script name.
sys.argv in python represents command line arguments.
Python sets the sys.argv to the python path only when you execute your script from an executable like python.exe. When you use python.exe, you specify the path of the script as a command line argument and hence in that scenario, sys.argv will contain the path of the script.
If you use Python in REPL mode, it will set the sys.argv to be empty string. Then, when you import your file and call the same function, you might have undesired behavior if any code assumes that sys.argv contains the path of the file being executed.
Calling a python function from TestStand is like importing the specified module and executing the specified function. There is no command line argument involved. Hence there will not be sys.argv.
As a workaround, when TestStand calls your module, you can set sys.argv and then continue the operation. This is the same workaround you need to when when you import the module in a python REPL and execute the function.
Thank you for your reply.
We have 4 different installations of TestStand and there is only one that does not set the sys.argv, all others return the sys.argv as an empty string. Some modules like tinker are complaining there is no value in sys.argv.
I would rather not update all my scripts to update sys.argv, however, I found an issue documented and the fix forces python to have something in the sys.argv https://bugs.python.org/issue32573
The fix is implemented in 3.8 and installing 3.8 fixes the issue for us but I want to avoid having multiple version of python for deployments.
How would TestStand enable REPL mode or have an empty string in sys.argv?