1+ import sys
12import pytest
23
3- from .utils import new_kernel , get_reply
4+ from .utils import TIMEOUT , new_kernel , get_reply
45
56seq = 0
67
78# Skip if debugpy is not available
89pytest .importorskip ("debugpy" )
910
1011
11- def wait_for_debug_request (kernel , command , arguments = None ):
12+ def wait_for_debug_request (kernel , command , arguments = None , full_reply = False ):
1213 """Carry out a debug request and return the reply content.
1314
1415 It does not check if the request was successful.
@@ -27,7 +28,7 @@ def wait_for_debug_request(kernel, command, arguments=None):
2728 )
2829 kernel .control_channel .send (msg )
2930 reply = get_reply (kernel , msg ["header" ]["msg_id" ], channel = "control" )
30- return reply ["content" ]
31+ return reply if full_reply else reply ["content" ]
3132
3233
3334@pytest .fixture
@@ -127,6 +128,76 @@ def test_set_breakpoints(kernel_with_debug):
127128 assert r ["success" ]
128129
129130
131+ def test_stop_on_breakpoint (kernel_with_debug ):
132+ code = """def f(a, b):
133+ c = a + b
134+ return c
135+
136+ f(2, 3)"""
137+
138+ r = wait_for_debug_request (kernel_with_debug , "dumpCell" , {"code" : code })
139+ source = r ["body" ]["sourcePath" ]
140+
141+ wait_for_debug_request (kernel_with_debug , "debugInfo" )
142+
143+ wait_for_debug_request (
144+ kernel_with_debug ,
145+ "setBreakpoints" ,
146+ {
147+ "breakpoints" : [{"line" : 2 }],
148+ "source" : {"path" : source },
149+ "sourceModified" : False ,
150+ },
151+ )
152+
153+ wait_for_debug_request (kernel_with_debug , "configurationDone" , full_reply = True )
154+
155+ kernel_with_debug .execute (code )
156+
157+ # Wait for stop on breakpoint
158+ msg = {"msg_type" : "" , "content" : {}}
159+ while msg .get ('msg_type' ) != 'debug_event' or msg ["content" ].get ("event" ) != "stopped" :
160+ msg = kernel_with_debug .get_iopub_msg (timeout = TIMEOUT )
161+
162+ assert msg ["content" ]["body" ]["reason" ] == "breakpoint"
163+
164+
165+ @pytest .mark .skipif (sys .version_info >= (3 , 10 ), reason = "TODO Does not work on Python 3.10" )
166+ def test_breakpoint_in_cell_with_leading_empty_lines (kernel_with_debug ):
167+ code = """
168+ def f(a, b):
169+ c = a + b
170+ return c
171+
172+ f(2, 3)"""
173+
174+ r = wait_for_debug_request (kernel_with_debug , "dumpCell" , {"code" : code })
175+ source = r ["body" ]["sourcePath" ]
176+
177+ wait_for_debug_request (kernel_with_debug , "debugInfo" )
178+
179+ wait_for_debug_request (
180+ kernel_with_debug ,
181+ "setBreakpoints" ,
182+ {
183+ "breakpoints" : [{"line" : 6 }],
184+ "source" : {"path" : source },
185+ "sourceModified" : False ,
186+ },
187+ )
188+
189+ wait_for_debug_request (kernel_with_debug , "configurationDone" , full_reply = True )
190+
191+ kernel_with_debug .execute (code )
192+
193+ # Wait for stop on breakpoint
194+ msg = {"msg_type" : "" , "content" : {}}
195+ while msg .get ('msg_type' ) != 'debug_event' or msg ["content" ].get ("event" ) != "stopped" :
196+ msg = kernel_with_debug .get_iopub_msg (timeout = TIMEOUT )
197+
198+ assert msg ["content" ]["body" ]["reason" ] == "breakpoint"
199+
200+
130201def test_rich_inspect_not_at_breakpoint (kernel_with_debug ):
131202 var_name = "text"
132203 value = "Hello the world"
0 commit comments