11
11
pytest .skip ("Terminal API tests time out on Windows." , allow_module_level = True )
12
12
13
13
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
+
14
22
@pytest .fixture
15
23
def terminal_path (tmp_path ):
16
24
subdir = tmp_path .joinpath ('terminal_path' )
@@ -61,7 +69,11 @@ async def test_terminal_create_with_kwargs(fetch, ws_fetch, terminal_path):
61
69
assert data ['name' ] == term_name
62
70
63
71
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
+ ):
65
77
resp = await fetch (
66
78
'api' , 'terminals' ,
67
79
method = 'POST' ,
@@ -75,21 +87,18 @@ async def test_terminal_create_with_cwd(fetch, ws_fetch, terminal_path):
75
87
ws = await ws_fetch (
76
88
'terminals' , 'websocket' , term_name
77
89
)
90
+ await ws .write_message (json .dumps (['stdin' , 'pwd\r ' ]))
78
91
79
- ws .write_message (json .dumps (['stdin' , 'pwd\r \n ' ]))
80
-
81
- message_stdout = ''
92
+ messages = ""
82
93
while True :
83
94
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 )
85
96
except asyncio .TimeoutError :
86
- break
97
+ return messages
87
98
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 ]
92
102
93
103
ws .close ()
94
-
95
- assert str (terminal_path ) in message_stdout
104
+ assert str (terminal_path ) in messages
0 commit comments