'Electron app won't start when using VSCode Test explorer

I am trying to setup python test environment (with pytest and selenium) for electron application. When running tests via VSCode Test Explorer I'm running into following error.

./tests/test_my_app.py::test_my_app Failed: [undefined]selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed.
  (chrome not reachable)
  (The process started from chrome location D:\Projects\Electorn-app\my-app\out\my-app-win32-x64\my-app.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
Backtrace:
    Ordinal0 [0x00496903+2517251]
    Ordinal0 [0x0042F8E1+2095329]
    Ordinal0 [0x00332848+1058888]
    Ordinal0 [0x0034DC70+1170544]
    Ordinal0 [0x0034A2CF+1155791]
    Ordinal0 [0x0037AAAF+1354415]
    Ordinal0 [0x0037A71A+1353498]
    Ordinal0 [0x0037639B+1336219]
    Ordinal0 [0x003527A7+1189799]
    Ordinal0 [0x00353609+1193481]
    GetHandleVerifier [0x00625904+1577972]
    GetHandleVerifier [0x006D0B97+2279047]
    GetHandleVerifier [0x00526D09+534521]
    GetHandleVerifier [0x00525DB9+530601]
    Ordinal0 [0x00434FF9+2117625]
    Ordinal0 [0x004398A8+2136232]
    Ordinal0 [0x004399E2+2136546]
    Ordinal0 [0x00443541+2176321]
    BaseThreadInitThunk [0x7676FA29+25]
    RtlGetAppContainerNamedObjectPath [0x773C7A9E+286]
    RtlGetAppContainerNamedObjectPath [0x773C7A6E+238]

but when i run

pytest ./tests

Or use launch configuration

"configurations": [
        {
            "name": "Python: Debug Tests",
            "type": "python",
            "request": "launch",
            "python": "${command:python.interpreterPath}",
            "module": "pytest",
            "console": "integratedTerminal",
            "justMyCode": false
        }

Application starts without problems.

Here is snippet of code that I try to run.

from selenium.webdriver.chrome.options import Options
from selenium import webdriver

def test_my_app():
    options = Options()
    options.add_argument("--remote-debugging-port=8315")
    options.binary_location = 'D:\Projects\Electorn-app\my-app\out\my-app-win32-x64\my-app.exe'
    
    driver = webdriver.Chrome(options=options)
    print(driver.title)
    driver.quit()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source