Skip to content

Commit 3fe8355

Browse files
committed
Always wait for jupyter to start in tests
1 parent 26b5854 commit 3fe8355

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

tests/test_offlinenotebook.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
import subprocess
66
from time import sleep
77
from urllib.request import urlopen
8+
from urllib.error import URLError
89

910
from selenium import webdriver
10-
from selenium.common.exceptions import TimeoutException, WebDriverException
11+
from selenium.common.exceptions import TimeoutException
1112
from selenium.webdriver.support.wait import WebDriverWait
1213
from selenium.webdriver.support import expected_conditions as EC
1314
from selenium.webdriver.common.by import By
@@ -87,6 +88,16 @@ def start_jupyter(self, jupyterdir, app):
8788
}
8889
self.jupyter_proc = subprocess.Popen(command, cwd=str(jupyterdir), env=env)
8990

91+
# Wait for Jupyter to start
92+
for n in range(10):
93+
sleep(1)
94+
try:
95+
with urlopen(f"http://localhost:{PORT}", timeout=2) as _:
96+
pass
97+
except URLError:
98+
continue
99+
print(f"jupyter-{app} started")
100+
90101
def initialise_firefox(self, downloaddir, url):
91102
profile = FirefoxProfile()
92103
profile.set_preference("browser.download.folderList", 2)
@@ -107,15 +118,7 @@ def initialise_firefox(self, downloaddir, url):
107118
self.driver = webdriver.Firefox(options=options)
108119
self.wait = WebDriverWait(self.driver, TIMEOUT)
109120

110-
# Jupyter may be slow to start
111-
for n in range(5):
112-
sleep(1)
113-
try:
114-
self.driver.get(url)
115-
except WebDriverException as exc:
116-
if "about:neterror" not in exc.msg:
117-
raise
118-
121+
self.driver.get(url)
119122
print("Firefox Initialized")
120123

121124
def initialise(self, tmpdir, app, url):
@@ -350,8 +353,6 @@ def test_offline_lab(self, tmpdir):
350353
class TestServer(FirefoxTestBase):
351354
def test_server_config(self, tmpdir):
352355
self.start_jupyter(tmpdir, "server")
353-
# Wait for server to start
354-
sleep(2)
355356

356357
with urlopen(CONFIG_URL) as r:
357358
assert json.load(r) == {

0 commit comments

Comments
 (0)