6
6
7
7
seq = 0
8
8
9
- # Skip if debugpy is not available
10
- pytest .importorskip ("debugpy" )
9
+ # Tests support debugpy not being installed, in which case the tests don't do anything useful
10
+ # functionally as the debug message replies are usually empty dictionaries, but they confirm that
11
+ # ipykernel doesn't block, or segfault, or raise an exception.
12
+ try :
13
+ import debugpy
14
+ except ImportError :
15
+ debugpy = None
11
16
12
17
13
18
def wait_for_debug_request (kernel , command , arguments = None , full_reply = False ):
@@ -85,15 +90,21 @@ def test_debug_initialize(kernel):
85
90
"locale" : "en" ,
86
91
},
87
92
)
88
- assert reply ["success" ]
93
+ if debugpy :
94
+ assert reply ["success" ]
95
+ else :
96
+ assert reply == {}
89
97
90
98
91
99
def test_attach_debug (kernel_with_debug ):
92
100
reply = wait_for_debug_request (
93
101
kernel_with_debug , "evaluate" , {"expression" : "'a' + 'b'" , "context" : "repl" }
94
102
)
95
- assert reply ["success" ]
96
- assert reply ["body" ]["result" ] == ""
103
+ if debugpy :
104
+ assert reply ["success" ]
105
+ assert reply ["body" ]["result" ] == ""
106
+ else :
107
+ assert reply == {}
97
108
98
109
99
110
def test_set_breakpoints (kernel_with_debug ):
@@ -104,7 +115,11 @@ def test_set_breakpoints(kernel_with_debug):
104
115
f(2, 3)"""
105
116
106
117
r = wait_for_debug_request (kernel_with_debug , "dumpCell" , {"code" : code })
107
- source = r ["body" ]["sourcePath" ]
118
+ if debugpy :
119
+ source = r ["body" ]["sourcePath" ]
120
+ else :
121
+ assert r == {}
122
+ source = "non-existent path"
108
123
109
124
reply = wait_for_debug_request (
110
125
kernel_with_debug ,
@@ -115,20 +130,29 @@ def test_set_breakpoints(kernel_with_debug):
115
130
"sourceModified" : False ,
116
131
},
117
132
)
118
- assert reply ["success" ]
119
- assert len (reply ["body" ]["breakpoints" ]) == 1
120
- assert reply ["body" ]["breakpoints" ][0 ]["verified" ]
121
- assert reply ["body" ]["breakpoints" ][0 ]["source" ]["path" ] == source
133
+ if debugpy :
134
+ assert reply ["success" ]
135
+ assert len (reply ["body" ]["breakpoints" ]) == 1
136
+ assert reply ["body" ]["breakpoints" ][0 ]["verified" ]
137
+ assert reply ["body" ]["breakpoints" ][0 ]["source" ]["path" ] == source
138
+ else :
139
+ assert reply == {}
122
140
123
141
r = wait_for_debug_request (kernel_with_debug , "debugInfo" )
124
142
125
143
def func (b ):
126
144
return b ["source" ]
127
145
128
- assert source in map (func , r ["body" ]["breakpoints" ])
146
+ if debugpy :
147
+ assert source in map (func , r ["body" ]["breakpoints" ])
148
+ else :
149
+ assert r == {}
129
150
130
151
r = wait_for_debug_request (kernel_with_debug , "configurationDone" )
131
- assert r ["success" ]
152
+ if debugpy :
153
+ assert r ["success" ]
154
+ else :
155
+ assert r == {}
132
156
133
157
134
158
def test_stop_on_breakpoint (kernel_with_debug ):
@@ -139,7 +163,11 @@ def test_stop_on_breakpoint(kernel_with_debug):
139
163
f(2, 3)"""
140
164
141
165
r = wait_for_debug_request (kernel_with_debug , "dumpCell" , {"code" : code })
142
- source = r ["body" ]["sourcePath" ]
166
+ if debugpy :
167
+ source = r ["body" ]["sourcePath" ]
168
+ else :
169
+ assert r == {}
170
+ source = "some path"
143
171
144
172
wait_for_debug_request (kernel_with_debug , "debugInfo" )
145
173
@@ -157,6 +185,10 @@ def test_stop_on_breakpoint(kernel_with_debug):
157
185
158
186
kernel_with_debug .execute (code )
159
187
188
+ if not debugpy :
189
+ # Cannot stop on breakpoint if debugpy not installed
190
+ return
191
+
160
192
# Wait for stop on breakpoint
161
193
msg : dict = {"msg_type" : "" , "content" : {}}
162
194
while msg .get ("msg_type" ) != "debug_event" or msg ["content" ].get ("event" ) != "stopped" :
@@ -175,7 +207,11 @@ def f(a, b):
175
207
f(2, 3)"""
176
208
177
209
r = wait_for_debug_request (kernel_with_debug , "dumpCell" , {"code" : code })
178
- source = r ["body" ]["sourcePath" ]
210
+ if debugpy :
211
+ source = r ["body" ]["sourcePath" ]
212
+ else :
213
+ assert r == {}
214
+ source = "some path"
179
215
180
216
wait_for_debug_request (kernel_with_debug , "debugInfo" )
181
217
@@ -193,6 +229,10 @@ def f(a, b):
193
229
194
230
kernel_with_debug .execute (code )
195
231
232
+ if not debugpy :
233
+ # Cannot stop on breakpoint if debugpy not installed
234
+ return
235
+
196
236
# Wait for stop on breakpoint
197
237
msg : dict = {"msg_type" : "" , "content" : {}}
198
238
while msg .get ("msg_type" ) != "debug_event" or msg ["content" ].get ("event" ) != "stopped" :
@@ -216,15 +256,21 @@ def test_rich_inspect_not_at_breakpoint(kernel_with_debug):
216
256
def func (v ):
217
257
return v ["name" ]
218
258
219
- assert var_name in list (map (func , r ["body" ]["variables" ]))
259
+ if debugpy :
260
+ assert var_name in list (map (func , r ["body" ]["variables" ]))
261
+ else :
262
+ assert r == {}
220
263
221
264
reply = wait_for_debug_request (
222
265
kernel_with_debug ,
223
266
"richInspectVariables" ,
224
267
{"variableName" : var_name },
225
268
)
226
269
227
- assert reply ["body" ]["data" ] == {"text/plain" : f"'{ value } '" }
270
+ if debugpy :
271
+ assert reply ["body" ]["data" ] == {"text/plain" : f"'{ value } '" }
272
+ else :
273
+ assert reply == {}
228
274
229
275
230
276
def test_rich_inspect_at_breakpoint (kernel_with_debug ):
@@ -235,7 +281,11 @@ def test_rich_inspect_at_breakpoint(kernel_with_debug):
235
281
f(2, 3)"""
236
282
237
283
r = wait_for_debug_request (kernel_with_debug , "dumpCell" , {"code" : code })
238
- source = r ["body" ]["sourcePath" ]
284
+ if debugpy :
285
+ source = r ["body" ]["sourcePath" ]
286
+ else :
287
+ assert r == {}
288
+ source = "some path"
239
289
240
290
wait_for_debug_request (
241
291
kernel_with_debug ,
@@ -253,6 +303,10 @@ def test_rich_inspect_at_breakpoint(kernel_with_debug):
253
303
254
304
kernel_with_debug .execute (code )
255
305
306
+ if not debugpy :
307
+ # Cannot stop on breakpoint if debugpy not installed
308
+ return
309
+
256
310
# Wait for stop on breakpoint
257
311
msg : dict = {"msg_type" : "" , "content" : {}}
258
312
while msg .get ("msg_type" ) != "debug_event" or msg ["content" ].get ("event" ) != "stopped" :
@@ -304,7 +358,11 @@ def my_test():
304
358
305
359
# Init debugger and set breakpoint
306
360
r = wait_for_debug_request (kernel_with_debug , "dumpCell" , {"code" : code })
307
- source = r ["body" ]["sourcePath" ]
361
+ if debugpy :
362
+ source = r ["body" ]["sourcePath" ]
363
+ else :
364
+ assert r == {}
365
+ source = "some path"
308
366
309
367
wait_for_debug_request (
310
368
kernel_with_debug ,
@@ -323,6 +381,10 @@ def my_test():
323
381
# Execute code
324
382
kernel_with_debug .execute (code )
325
383
384
+ if not debugpy :
385
+ # Cannot stop on breakpoint if debugpy not installed
386
+ return
387
+
326
388
# Wait for stop on breakpoint
327
389
msg : dict = {"msg_type" : "" , "content" : {}}
328
390
while msg .get ("msg_type" ) != "debug_event" or msg ["content" ].get ("event" ) != "stopped" :
0 commit comments