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

Function test_attach_api

tests/debugpy/test_attach.py:19–105  ·  view source on GitHub ↗
(pyfile, host, wait_for_client, is_client_connected, stop_method)

Source from the content-addressed store, hash-verified

17@pytest.mark.parametrize("host", ["127.0.0.1", "::1"])
18@pytest.mark.parametrize("wait_for_client", ["wait_for_client", pytest.param("", marks=pytest.mark.skipif(sys.platform.startswith("darwin"), reason="Flakey test on Mac"))])
19def test_attach_api(pyfile, host, wait_for_client, is_client_connected, stop_method):
20 @pyfile
21 def code_to_debug():
22 import debuggee
23 import debugpy
24 import sys
25 import time
26 from debuggee import backchannel, scratchpad
27
28 # Test different ways of calling configure().
29 debugpy.configure(qt="none", subProcess=True, python=sys.executable)
30 debugpy.configure({"qt": "none", "subProcess": True, "python": sys.executable})
31 debugpy.configure({"qt": "none"}, python=sys.executable)
32
33 debuggee.setup()
34 _, host, port, wait_for_client, is_client_connected, stop_method = sys.argv
35 port = int(port)
36 debugpy.listen(address=(host, port))
37
38 if wait_for_client:
39 backchannel.send("wait_for_client")
40 debugpy.wait_for_client()
41
42 if is_client_connected:
43 backchannel.send("is_client_connected")
44 while not debugpy.is_client_connected():
45 print("looping until is_client_connected()")
46 time.sleep(0.1)
47
48 if stop_method == "breakpoint":
49 backchannel.send("breakpoint?")
50 assert backchannel.receive() == "proceed"
51 debugpy.breakpoint()
52 print("break") # @breakpoint
53 else:
54 scratchpad["paused"] = False
55 backchannel.send("loop?")
56 assert backchannel.receive() == "proceed"
57 while not scratchpad["paused"]:
58 print("looping until paused")
59 time.sleep(0.1)
60
61 with debug.Session() as session:
62 host = runners.attach_connect.host if host == "127.0.0.1" else host
63 port = runners.attach_connect.port
64 session.config.update({"connect": {"host": host, "port": port}})
65
66 backchannel = session.open_backchannel()
67 session.spawn_debuggee(
68 [
69 code_to_debug,
70 host,
71 port,
72 wait_for_client,
73 is_client_connected,
74 stop_method,
75 ]
76 )

Callers

nothing calls this directly

Calls 12

open_backchannelMethod · 0.80
spawn_debuggeeMethod · 0.80
expect_server_socketMethod · 0.80
connect_to_adapterMethod · 0.80
request_attachMethod · 0.80
receiveMethod · 0.80
wait_for_stopMethod · 0.80
request_continueMethod · 0.80
updateMethod · 0.45
sendMethod · 0.45
requestMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…