Skip to content
This repository was archived by the owner on Jun 22, 2025. It is now read-only.

Commit e524660

Browse files
authored
Fixed Tests v2 (#651)
Fix tests for Windows
1 parent eb705d1 commit e524660

File tree

6 files changed

+46
-13
lines changed

6 files changed

+46
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
__pycache__
22
dist
33
build
4+
Drivers
45
Eel.egg-info
56
.tmp
67
.DS_Store

requirements-test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ psutil==5.9.2
44
pytest==7.0.1
55
pytest-timeout==2.1.0
66
selenium==3.141.0
7+
webdriver_manager==3.7.1

tests/conftest.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import os
2+
import platform
23
from unittest import mock
34

45
import pytest
56
from selenium import webdriver
67
from selenium.webdriver import DesiredCapabilities
8+
from webdriver_manager.chrome import ChromeDriverManager
79

810

911
@pytest.fixture
@@ -14,9 +16,17 @@ def driver():
1416
options = webdriver.ChromeOptions()
1517
options.headless = True
1618
capabilities = DesiredCapabilities.CHROME
17-
capabilities['goog:loggingPrefs'] = {"browser": "ALL"}
19+
capabilities["goog:loggingPrefs"] = {"browser": "ALL"}
1820

19-
driver = webdriver.Chrome(options=options, desired_capabilities=capabilities, service_log_path=os.path.devnull)
21+
if platform.system() == "Windows":
22+
options.binary_location = "C:/Program Files/Google/Chrome/Application/chrome.exe"
23+
24+
driver = webdriver.Chrome(
25+
ChromeDriverManager().install(),
26+
options=options,
27+
desired_capabilities=capabilities,
28+
service_log_path=os.path.devnull,
29+
)
2030

2131
# Firefox doesn't currently supported pulling JavaScript console logs, which we currently scan to affirm that
2232
# JS/Python can communicate in some places. So for now, we can't really use firefox/geckodriver during testing.

tests/integration/test_examples.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import time
23
from tempfile import TemporaryDirectory, NamedTemporaryFile
34

45
from selenium import webdriver
@@ -47,6 +48,7 @@ def test_04_file_access(driver: webdriver.Remote):
4748
with TemporaryDirectory() as temp_dir, NamedTemporaryFile(dir=temp_dir) as temp_file:
4849
driver.find_element_by_id('input-box').clear()
4950
driver.find_element_by_id('input-box').send_keys(temp_dir)
51+
time.sleep(0.5)
5052
driver.find_element_by_css_selector('button').click()
5153

5254
assert driver.find_element_by_id('file-name').text == os.path.basename(temp_file.name)

tests/utils.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import contextlib
22
import os
3+
import sys
4+
import platform
35
import subprocess
46
import tempfile
57
import time
@@ -8,15 +10,30 @@
810
import psutil
911

1012
# Path to the test data folder.
11-
TEST_DATA_DIR = Path(__file__).parent / 'data'
13+
TEST_DATA_DIR = Path(__file__).parent / "data"
1214

1315

1416
def get_process_listening_port(proc):
15-
psutil_proc = psutil.Process(proc.pid)
16-
while not any(conn.status == 'LISTEN' for conn in psutil_proc.connections()):
17-
time.sleep(0.01)
18-
19-
conn = next(filter(lambda conn: conn.status == 'LISTEN', psutil_proc.connections()))
17+
conn = None
18+
if platform.system() == "Windows":
19+
current_process = psutil.Process(proc.pid)
20+
children = []
21+
while children == []:
22+
time.sleep(0.01)
23+
children = current_process.children(recursive=True)
24+
if (3, 6) <= sys.version_info < (3, 7):
25+
children = [current_process]
26+
for child in children:
27+
while child.connections() == [] and not any(conn.status == "LISTEN" for conn in child.connections()):
28+
time.sleep(0.01)
29+
30+
conn = next(filter(lambda conn: conn.status == "LISTEN", child.connections()))
31+
else:
32+
psutil_proc = psutil.Process(proc.pid)
33+
while not any(conn.status == "LISTEN" for conn in psutil_proc.connections()):
34+
time.sleep(0.01)
35+
36+
conn = next(filter(lambda conn: conn.status == "LISTEN", psutil_proc.connections()))
2037
return conn.laddr.port
2138

2239

@@ -40,8 +57,10 @@ def get_eel_server(example_py, start_html):
4057
4158
import {os.path.splitext(os.path.basename(example_py))[0]}
4259
""")
43-
44-
proc = subprocess.Popen(['python', test.name], cwd=os.path.dirname(example_py))
60+
proc = subprocess.Popen(
61+
[sys.executable, test.name],
62+
cwd=os.path.dirname(example_py),
63+
)
4564
eel_port = get_process_listening_port(proc)
4665

4766
yield f"http://localhost:{eel_port}/{start_html}"

tox.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
envlist = py36,py37,py38,py39,py310
33

44
[pytest]
5-
timeout = 5
5+
timeout = 30
66

77
[gh-actions]
88
python =
@@ -17,5 +17,5 @@ deps = -r requirements-test.txt
1717
commands =
1818
# this ugly hack is here because:
1919
# https://github.com/tox-dev/tox/issues/149
20-
pip install -q -r {toxinidir}/requirements-test.txt
21-
{envpython} -m pytest {posargs}
20+
pip install -q -r '{toxinidir}'/requirements-test.txt
21+
'{envpython}' -m pytest {posargs}

0 commit comments

Comments
 (0)