Python Adaptor in TestStand

I wrote a recent post about calling Python from LabVIEW. As it turns out you can also call Python directly from Test Stand as well. In TestStand 2019 a new Python Adaptor was added. Rather than create my own example, I will just point you to the shipping example. It’s pretty good. What I’d rather talk about briefly is how to set up the adaptor and the differences between calling Python in TestStand and LabVIEW.

Here is the example in TestStand Help. Just search for Python.

Adaptor Settings

Python Adaptor Settings

So the first settings are the interpreter settings. You can use one global session or you can use a separate session per thread or execution. In the adaptor settings screen you must select a single Python Version. This dialog also lets you point TestStand to a Virtual Environment. In addition, you can decide whether you want to display the console or not. That can be useful for debugging. You can also select the module viewer and point it to an IDE like Pycharm or your favorite text editor.

Per step advanced settings.

The other thing worth noting is that on any Python step you can spawn a new interpreter session and store it in a Teststand variable and then use that on subsequent steps. To set the interpreter for a particular step, go to its module tab, and to the right of the dropdown where you select the python module, click on the advanced button. Note that this will let you call different versions of Python from TestStand at the same time.

Differences with LabVIEW

We have already discussed the biggest difference between calling Python in LabVIEW and Teststand and that is that TestStand supports Virtual Environments. This is pretty huge.

There is another difference and that is that TestStand supports Python Objects. So you can retrieve an object from a Python method and store it in a TestStand variable for future use. Of course you must use it inside the same Python Interpreter Session for it to be valid.

If you need help integrating Python with either LabVIEW or TestStand, please reach out. We’d love to talk to you.

2 Comments on “Python Adaptor in TestStand

  1. It would be nice if you might provide an example of how, using the python adapter, we might pass command line arguments to a python script. It would also be nice if you could show us how stdin and stdout can be sent/captured by teststand from a pythin script invoked through the adapter.

    I have a (very) simple python script that adds it’s command line arguments and displays info on stdout. I’d like to know how to implement that connectivity using the teststand python adapter. The only online doc I could find at NI basically said to use the ‘call executable’ step type. So why bother to have the Python adapter at all?

    Here’s my dummy test script:
    import sys

    def addargs():
    print('Entering Python script: ', sys.argv[0], 'Num Args: ', len(sys.argv))
    if n>0:
    for i in range(1,n):
    if i != 1:
    print(' + ', sys.argv[i], end='')
    print(sys.argv[i], end='')
    sum += int(sys.argv[i])
    print(" = ", sum)
    print('No numbers to add!')


    • Gary,
      The python adaptor does not have a way to pass in CLI arguments, you need to do that via the System Exec call in LabVIEW or the call executable step type in TestStand.

      If you wanted to adapt your script, you could write your function as a regular python function with regular parameters. Then have a wrapper for it that reads in the CLI arguments and then calls your function and passes it the CLI Parameters. If there are any parameters passed in call that script. Then you could call the function directly from LV or TestStand using the Python node. You could also do something similar with the output.

Leave a Reply

Your email address will not be published. Required fields are marked *