Skip to content

Commit 24da3cd

Browse files
authored
Feedback from #26679 / #26680 (#26694)
The changes from #26679 were mistakenly landed as part of #26680 This change applies the feedback from #26679
1 parent ac48e38 commit 24da3cd

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

test/test_sockets.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ def __init__(self, filename, args, listen_port, do_server_check=True):
7575
self.do_server_check = do_server_check
7676

7777
def __enter__(self):
78+
try:
79+
import websockify # type: ignore # noqa: PLC0415
80+
except ModuleNotFoundError:
81+
raise Exception('Unable to import module websockify. Run "python3 -m pip install websockify" or set environment variable EMTEST_SKIP_PYTHON_DEV_PACKAGES=1 to skip this test.') from None
82+
7883
# compile the server
7984
# NOTE empty filename support is a hack to support
8085
# the current test_enet
@@ -85,11 +90,6 @@ def __enter__(self):
8590
process = Popen([os.path.abspath('server')])
8691
self.processes.append(process)
8792

88-
try:
89-
import websockify # type: ignore # noqa: PLC0415
90-
except ModuleNotFoundError:
91-
raise Exception('Unable to import module websockify. Run "python3 -m pip install websockify" or set environment variable EMTEST_SKIP_PYTHON_DEV_PACKAGES=1 to skip this test.') from None
92-
9393
# start the websocket proxy
9494
print('running websockify on %d, forward to tcp %d' % (self.listen_port, self.target_port), file=sys.stderr)
9595
# source_is_ipv6=True here signals to websockify that it should prefer ipv6 address when
@@ -111,6 +111,7 @@ def __enter__(self):
111111
except OSError:
112112
time.sleep(1)
113113
else:
114+
self.clean_processes()
114115
raise Exception('[Websockify failed to start up in a timely manner]')
115116

116117
print('[Websockify on process %s]' % str(self.processes[-2:]))
@@ -123,6 +124,9 @@ def __exit__(self, *args, **kwargs):
123124
self.websockify.join()
124125

125126
# clean up any processes we started
127+
self.clean_processes()
128+
129+
def clean_processes(self):
126130
for p in self.processes:
127131
clean_process(p)
128132

0 commit comments

Comments
 (0)