MCPcopy Create free account
hub / github.com/microsoft/debugpy / test_attach_pid_client

Function test_attach_pid_client

tests/debugpy/test_attach.py:209–268  ·  view source on GitHub ↗
(pyfile, target, pid_type)

Source from the content-addressed store, hash-verified

207)
208@pytest.mark.flaky(retries=2, delay=1)
209def test_attach_pid_client(pyfile, target, pid_type):
210 @pyfile
211 def code_to_debug():
212 import debuggee
213 import time
214
215 debuggee.setup()
216
217 def do_something(i):
218 time.sleep(0.2)
219 proceed = True
220 print(i) # @bp
221 return proceed
222
223 for i in range(500):
224 if not do_something(i):
225 break
226
227 def before_request(command, arguments):
228 if command == "attach":
229 assert isinstance(arguments["processId"], int)
230 if pid_type == "str":
231 arguments["processId"] = str(arguments["processId"])
232
233 session1 = debug.Session()
234
235 session1.before_request = before_request
236 session1.config["redirectOutput"] = True
237
238 session1.captured_output = set()
239 session1.expected_exit_code = None # not expected to exit on disconnect
240
241 with session1.attach_pid(target(code_to_debug), wait=False):
242 session1.set_breakpoints(code_to_debug, all)
243
244 session1.wait_for_stop(expected_frames=[some.dap.frame(code_to_debug, "bp")])
245
246 pid = session1.config["processId"]
247
248 # Note: don't call session1.disconnect because it'd deadlock in channel.close()
249 # (because the fd is in a read() in a different thread, we can't call close() on it).
250 session1.request("disconnect")
251 session1.wait_for_terminated()
252
253 with debug.Session() as session2:
254 with session2.attach_pid(pid, wait=False):
255 session2.set_breakpoints(code_to_debug, all)
256
257 stop = session2.wait_for_stop(
258 expected_frames=[some.dap.frame(code_to_debug, "bp")]
259 )
260
261 # Remove breakpoint and continue.
262 session2.set_breakpoints(code_to_debug, [])
263 session2.request(
264 "setExpression",
265 {"frameId": stop.frame_id, "expression": "proceed", "value": "False"},
266 )

Callers

nothing calls this directly

Calls 7

set_breakpointsMethod · 0.95
wait_for_stopMethod · 0.95
requestMethod · 0.95
wait_for_terminatedMethod · 0.95
request_continueMethod · 0.80
targetFunction · 0.70
requestMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…