1111import pytest
1212from jupyter_client .blocking .client import BlockingKernelClient
1313
14- from .utils import TIMEOUT , assemble_output , get_replies , get_reply , new_kernel , flush_channels
14+ from .utils import TIMEOUT , assemble_output , flush_channels , get_replies , get_reply , new_kernel
1515
1616# Helpers
1717
@@ -40,7 +40,9 @@ def list_subshell_helper(kc: BlockingKernelClient):
4040 return reply ["content" ]
4141
4242
43- def execute_request (kc : BlockingKernelClient , code : str , subshell_id : str | None , silent : bool = False ):
43+ def execute_request (
44+ kc : BlockingKernelClient , code : str , subshell_id : str | None , silent : bool = False
45+ ):
4446 msg = kc .session .msg ("execute_request" , {"code" : code , "silent" : silent })
4547 msg ["header" ]["subshell_id" ] = subshell_id
4648 kc .shell_channel .send (msg )
@@ -260,6 +262,7 @@ def test_execute_stop_on_error(are_subshells):
260262 if subshell_id :
261263 delete_subshell_helper (kc , subshell_id )
262264
265+
263266def test_silent_flag_in_subshells ():
264267 """Verifies that the 'silent' flag suppresses output in main and subshell contexts."""
265268 with new_kernel () as kc :
@@ -269,22 +272,24 @@ def test_silent_flag_in_subshells():
269272 # Test silent execution in main shell
270273 msg_main_silent = execute_request (kc , "a=1" , None , silent = True )
271274 reply_main_silent = get_reply (kc , msg_main_silent ["header" ]["msg_id" ])
272- assert reply_main_silent [' content' ][ ' status' ] == 'ok'
275+ assert reply_main_silent [" content" ][ " status" ] == "ok"
273276
274277 # Test silent execution in subshell
275278 subshell_id = create_subshell_helper (kc )["subshell_id" ]
276279 msg_sub_silent = execute_request (kc , "b=2" , subshell_id , silent = True )
277280 reply_sub_silent = get_reply (kc , msg_sub_silent ["header" ]["msg_id" ])
278- assert reply_sub_silent [' content' ][ ' status' ] == 'ok'
281+ assert reply_sub_silent [" content" ][ " status" ] == "ok"
279282
280283 # Check for no iopub messages (other than status) from the silent requests
281284 for msg_id in [msg_main_silent ["header" ]["msg_id" ], msg_sub_silent ["header" ]["msg_id" ]]:
282285 while True :
283286 try :
284287 msg = kc .get_iopub_msg (timeout = 0.2 )
285- if msg [' header' ][ ' msg_type' ] == ' status' :
288+ if msg [" header" ][ " msg_type" ] == " status" :
286289 continue
287- pytest .fail (f"Silent execution produced unexpected IOPub message: { msg ['header' ]['msg_type' ]} " )
290+ pytest .fail (
291+ f"Silent execution produced unexpected IOPub message: { msg ['header' ]['msg_type' ]} "
292+ )
288293 except Empty :
289294 break
290295
@@ -308,12 +313,14 @@ def test_silent_flag_in_subshells():
308313 while True :
309314 try :
310315 msg = kc .get_iopub_msg (timeout = 0.2 )
311- if msg [' header' ][ ' msg_type' ] == ' status' :
312- if msg [' parent_header' ].get (' msg_id' ) == msg_silent [' header' ][ ' msg_id' ]:
313- continue
316+ if msg [" header" ][ " msg_type" ] == " status" :
317+ if msg [" parent_header" ].get (" msg_id" ) == msg_silent [" header" ][ " msg_id" ]:
318+ continue
314319 # Any other message related to the silent request is a failure
315- if msg ['parent_header' ].get ('msg_id' ) == msg_silent ['header' ]['msg_id' ]:
316- pytest .fail ("Silent execution in concurrent setting produced unexpected IOPub message" )
320+ if msg ["parent_header" ].get ("msg_id" ) == msg_silent ["header" ]["msg_id" ]:
321+ pytest .fail (
322+ "Silent execution in concurrent setting produced unexpected IOPub message"
323+ )
317324 except Empty :
318325 break
319326 finally :
0 commit comments