NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Python system arguments not passed (argv empty)

Hi!

I am using TestStand 2019 f2 (19.0.0.170 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: 

<class 'IndexError'>
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[0])IndexError: list index out of range

 

The sys.argv[0] 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. 

 

Best regards

 

0 Kudos
Message 1 of 5
(4,862 Views)

It would help if we can see how you set up the "Call Executable" step. I'm assuming that's how you are calling it since you are using argv?

0 Kudos
Message 2 of 5
(4,826 Views)

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[0] but the list is empty where I'm expecting the script name.

0 Kudos
Message 3 of 5
(4,260 Views)

sys.argv in python represents command line arguments.

 

Python sets the sys.argv[0] 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[0] will contain the path of the script.

 

If you use Python in REPL mode, it will set the sys.argv[0] 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[0] 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[0].

 

As a workaround, when TestStand calls your module, you can set sys.argv[0] 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.

 

-Shashidhar

Message 4 of 5
(4,241 Views)

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[0] as an empty string. Some modules like tinker are complaining there is no value in sys.argv[0].

 

I would rather not update all my scripts to update sys.argv[0], 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[0]?

0 Kudos
Message 5 of 5
(4,235 Views)