NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

TestStand call python function, change some strings in python function, but TestStand's result is the old string, not update

Solved!
Go to solution

Have a python function, be called by TestStand, and change the string in the python, run the TestStand, but TestStand's result is the old string, not update the new string.

Except close the TestStand software and restart it, the result will update to the new string.

Is there any other way to update changes in python functions in real time?

0 Kudos
Message 1 of 7
(1,008 Views)
Solution
Accepted by Jmknode77

Any changes to the python file require TestStand to reload it. Typically, you can force it to unload by selecting File -> Unload all modules or use the Reload module option in Step Settings

 

santo_13_0-1675353535336.png

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
Message 2 of 7
(976 Views)

Thank you for your reply.

By selecting [File -> Unload all modules] this method is solved this problem.

 

 

The method in the picture you replied has also been tried, but the new string has not been updated, this method may not work.

Message 3 of 7
(960 Views)

It is 2 years later and I have the exact same issue with changing python code modules and re-running teststand 2023 Q4 64 bit.  The use of the file>unload all modules does seem to force the reload of the python module the question remains as to why the "Reload Module and Prototype" button fails to work.  I have spent hours and hours figuring out that it seems not to work.  Why not just remove it?  Then, make the unload modules function run automatically, every time?  IS there something I don't get?  Am I setting up my python module incorrectly?

0 Kudos
Message 4 of 7
(75 Views)

Allow me to also add....

When you change the python module to add a new function and save it,  then add a TestStand step that references the new code, TestStand pick up the new methods to be used in the step.  It is when you execute that sequence that it will say that there is no reference to that method in the class.  It is like it knows it is there for editing but not for execution.

0 Kudos
Message 5 of 7
(74 Views)

"Reload Module and Prototype" purpose is to check compatibility between what is configured in step settings pane and what exists in the Python file. It does not reload any modified file.

 

In Python, even if there are multiple import statement to a file, the file is loaded/imported only once. This is true even if you modify the file in between import statements. If you want to use updated file in Python, you have to use new instance of Python.

 

When using Python in TestStand, you can do the following so that you always use the latest code for execution:

  • Option 1 - In Python adapter settings, enable `Reload modified modules before execution`.
    • Whenever a Python step is executed, it will check if the module to be called is modified or not and reload the module if required.
  • Option 2 - Use Python adapter settings and/or advanced settings in Python step to configure the Python session to be used for execution
    • If you configure something like, always execute the step in a new Python session, you will always load the latest code.

 

Note: In step settings pane for Python step, to populate the existing class/function/parameters, we parse the code. Hence, when you add a new method in your code, we pick it up and display them in the step settings pane.

 

-Shashidhar

Message 6 of 7
(19 Views)

Thanks!  I used Option 1 and it works fine.  This just wasn't obvious to me.

0 Kudos
Message 7 of 7
(14 Views)