Logic 2.4.7 Error using .launch() from Unittest

import unittest
import time
from saleae import automation

def main():
    logic_2 = automation.Manager.launch()
    time.sleep(10)
    logic_2.close()

class TestLogicLaunch(unittest.TestCase):

    def test_logic_launch(self):
        logic_2 = automation.Manager.launch()
        time.sleep(10)
        logic_2.close()


if __name__ == '__main__':
    main()

I have simplified my code to the simplest version to demonstrate the problem. In the code above, when I run the program from the terminal, thus just executing the main function, the program executes without error, producing the result:

INFO:saleae.automation.manager:sub ChannelConnectivity.IDLE
INFO:saleae.automation.manager:sub ChannelConnectivity.CONNECTING
INFO:saleae.automation.manager:sub ChannelConnectivity.TRANSIENT_FAILURE
INFO:saleae.automation.manager:sub ChannelConnectivity.READY

However, when I run the same code in a test case(as the test_logic_launch function, using vscode’s testcase runner) the automation.Manager.launch() function fails to execute producing the following error:

test_logic_launch (Logic2_launch_test.TestLogicLaunch) ... ERROR
NoneType: None

======================================================================
ERROR: test_logic_launch (Logic2_launch_test.TestLogicLaunch)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\Users\jmansky\Desktop\Logic2_launch_test.py", line 13, in test_logic_launch
    logic_2 = automation.Manager.launch()
  File "C:\Users\jmansky\AppData\Local\Programs\Python\Python39-32\lib\site-packages\saleae\automation\manager.py", line 384, in launch
    return cls(
  File "C:\Users\jmansky\AppData\Local\Programs\Python\Python39-32\lib\site-packages\saleae\automation\manager.py", line 310, in __init__
    raise exc from None
  File "C:\Users\jmansky\AppData\Local\Programs\Python\Python39-32\lib\site-packages\saleae\automation\manager.py", line 290, in __init__
    app_info = self.get_app_info()
  File "C:\Users\jmansky\AppData\Local\Programs\Python\Python39-32\lib\site-packages\saleae\automation\manager.py", line 417, in get_app_info
    reply: saleae_pb2.GetAppInfoReply = self.stub.GetAppInfo(saleae_pb2.GetAppInfoRequest())
  File "C:\Users\jmansky\AppData\Local\Programs\Python\Python39-32\lib\site-packages\grpc\_channel.py", line 1030, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "C:\Users\jmansky\AppData\Local\Programs\Python\Python39-32\lib\site-packages\grpc\_channel.py", line 910, in _end_unary_response_blocking
    raise _InactiveRpcError(state)  # pytype: disable=not-instantiable
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
	status = StatusCode.UNAVAILABLE
	details = "failed to connect to all addresses; last error: UNAVAILABLE: ipv4:127.0.0.1:10430: WSA Error"
	debug_error_string = "UNKNOWN:failed to connect to all addresses; last error: UNAVAILABLE: ipv4:127.0.0.1:10430: WSA Error {created_time:"2023-06-09T15:20:54.490186608+00:00", grpc_status:14}"
>

----------------------------------------------------------------------
Ran 1 test in 21.201s

FAILED (errors=1)

I do not understand why running the launch function inside of unittest would cause this error to occur. Any help or potential solutions would be greatly appreciated.

@joshmansky Sorry for the trouble with that. Another user posted a similar looking error in the forum post below. There were attempting to launch their script using Windows 10 SSH Server:

In short, my hunch is that testcase runner doesn’t have proper access to run our software’s GUI. Let me run this by our software team next week and we’ll share a follow up.

I have tried that solution, but I have not figured out how to run psexec commands from a test case. However, I am sure I am doing something wrong as I am new to ssh and psexec. Also, let me know if there is some other way to launch the logic2 software from a python unittest testcase.

Hi @joshmansky,

I can reproduce your problem over here. This is very odd. It looks like the root problem is that when our library attempts to start the installed version of Logic 2 using subprocess.Popen, nothing happens. Then shortly after that, our attempt to connect to the process fails (because it’s not running).

Also, I think this is caused by VS Code and not by unittest. If I run your test from the command line by making the following change to your code, it still works properly, and reports that the test ran.

if __name__ == '__main__':
    # main()
    unittest.main()
----------------------------------------------------------------------
Ran 1 test in 13.207s

OK

With more testing, I can confirm the problem is specifically with subprocess.Popen and VS code. Here is my test code:

import subprocess
import unittest
import time
from saleae import automation


def main():
    logic_2 = automation.Manager.launch()
    time.sleep(10)
    logic_2.close()


class TestLogicLaunch(unittest.TestCase):

    def test_logic_launch(self):
        logic_2 = automation.Manager.launch()
        time.sleep(10)
        logic_2.close()

    def test_logic2_launch(self):
        logic2_bin = '/Program Files/Logic/Logic.exe'
        process = subprocess.Popen([logic2_bin])
        process.wait()


if __name__ == '__main__':
    main()

If I run that new test from the command line like so, Popen opens Logic 2:

python -m unittest test_test.TestLogicLaunch.test_logic2_launch

However running the same test from VS code never launches Logic 2, but it passes immidiately.

However, I can confirm that VS code is able to launch other applications like notepad.exe:

    def test_logic2_launch(self):
        # logic2_bin = '/Program Files/Logic/Logic.exe'
        logic2_bin = 'notepad.exe'
        process = subprocess.Popen([logic2_bin])
        process.wait()

My first guess is that there might be an issue with launching an electron process from another existing electron process. To test this, I have a few other Electron apps installed, including the app from notion.so, and tested that. Same result. However, other electron apps like Slack and Figma are able to launch just fine, so I really don’t know what the pattern is here.

Here is my final test file. Notion.exe and Logic.exe both failed to launch, the rest did launch from vs code.

import subprocess
import unittest


class TestExeLaunch(unittest.TestCase):

    def test_notepad_launch(self):
        process = subprocess.Popen(['notepad.exe'])
        process.wait()

    def test_notion_launch(self):
        process = subprocess.Popen(
            ['/Users/markg/AppData/Local/Programs/Notion/Notion.exe'])
        process.wait()

    def test_saleae_launch(self):
        process = subprocess.Popen(['/Program Files/Logic/Logic.exe'])
        process.wait()

    def test_slack_launch(self):
        process = subprocess.Popen(
            ['/Users/markg/AppData/Local/slack/slack.exe'])
        process.wait()

    def test_figma_launch(self):
        process = subprocess.Popen(
            ["/Users/markg/AppData/Local/Figma/app-116.10.8/Figma.exe"])
        process.wait()

    def test_firefox_launch(self):
        process = subprocess.Popen(
            ["/Program Files/Mozilla Firefox/firefox.exe"])
        process.wait()


if __name__ == '__main__':
    unittest.main()

Anyway a quick solution here is to simply start the Logic 2 software and leave it running in the background with the automation server enabled, then use the connect function to connect to the existing app.

    def test_existing_logic2(self):
        manager = automation.Manager.connect()
        info = manager.get_app_info()
        self.assertEqual(info.app_version, '2.4.7')
        manager.close()

That works properly from vs code and from the command line.

I don’t know what this means for an electro application, but in the ‘not working’ case there is an extra environment variable: ELECTRON_RUN_AS_NODE=1
This might give a clue as to why it is not working @markgarrison

1 Like

Nice Catch! That was the problem!

First I was able to reproduce the problem from the command line simply by setting that variable, then attempting to launch Logic.exe.

A quick fix in python is to delete the environment variable before launching Logic, like so:

del os.environ['ELECTRON_RUN_AS_NODE']

Just do that before calling automation.Manager.launch() and it should work! I tested and confirmed this from vs code.