Skip to content

Commit c74f660

Browse files
committed
add fixture to kill all terminals after each test
1 parent 6d909ca commit c74f660

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

tests/test_terminal.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
pytest.skip("Terminal API tests time out on Windows.", allow_module_level=True)
1212

1313

14+
# Kill all running terminals after each test to avoid cross-test issues
15+
# with still running terminals.
16+
@pytest.fixture(autouse=True)
17+
async def kill_all(serverapp):
18+
yield
19+
await serverapp.web_app.settings["terminal_manager"].kill_all()
20+
21+
1422
@pytest.fixture
1523
def terminal_path(tmp_path):
1624
subdir = tmp_path.joinpath('terminal_path')
@@ -61,7 +69,11 @@ async def test_terminal_create_with_kwargs(fetch, ws_fetch, terminal_path):
6169
assert data['name'] == term_name
6270

6371

64-
async def test_terminal_create_with_cwd(fetch, ws_fetch, terminal_path):
72+
async def test_terminal_create_with_cwd(
73+
fetch,
74+
ws_fetch,
75+
terminal_path
76+
):
6577
resp = await fetch(
6678
'api', 'terminals',
6779
method='POST',
@@ -75,21 +87,18 @@ async def test_terminal_create_with_cwd(fetch, ws_fetch, terminal_path):
7587
ws = await ws_fetch(
7688
'terminals', 'websocket', term_name
7789
)
90+
await ws.write_message(json.dumps(['stdin', 'pwd\r']))
7891

79-
ws.write_message(json.dumps(['stdin', 'pwd\r\n']))
80-
81-
message_stdout = ''
92+
messages = ""
8293
while True:
8394
try:
84-
message = await asyncio.wait_for(ws.read_message(), timeout=1.0)
95+
response = await asyncio.wait_for(ws.read_message(), timeout=1.0)
8596
except asyncio.TimeoutError:
86-
break
97+
return messages
8798

88-
message = json.loads(message)
89-
90-
if message[0] == 'stdout':
91-
message_stdout += message[1]
99+
response = json.loads(response)
100+
if response[0] == "stdout":
101+
messages += response[1]
92102

93103
ws.close()
94-
95-
assert str(terminal_path) in message_stdout
104+
assert str(terminal_path) in messages

0 commit comments

Comments
 (0)