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

Function test_sudo

tests/debugpy/test_run.py:140–182  ·  view source on GitHub ↗
(pyfile, tmpdir, run, target)

Source from the content-addressed store, hash-verified

138@pytest.mark.skipif(sys.platform == "win32", reason="sudo not available on Windows")
139@pytest.mark.parametrize("run", runners.all_launch)
140def test_sudo(pyfile, tmpdir, run, target):
141 # Since the test can't rely on sudo being allowed for the user, create a dummy
142 # sudo script that doesn't actually elevate, but sets an environment variable
143 # that can be checked in the debuggee.
144 sudo = tmpdir / "sudo"
145 sudo.write(
146 """#!/bin/sh
147 if [ "$1" = "-E" ]; then shift; fi
148 exec env DEBUGPY_SUDO=1 "$@"
149 """
150 )
151 os.chmod(sudo.strpath, 0o777)
152
153 @pyfile
154 def code_to_debug():
155 import os
156
157 import debuggee
158 from debuggee import backchannel
159
160 debuggee.setup()
161 backchannel.send(os.getenv("DEBUGPY_SUDO", "0"))
162
163 with debug.Session() as session:
164 session.config["sudo"] = True
165 session.spawn_adapter.env["PATH"] = session.spawn_debuggee.env["PATH"] = (
166 tmpdir.strpath + ":" + os.environ["PATH"]
167 )
168
169 backchannel = session.open_backchannel()
170 with run(session, target(code_to_debug)):
171 pass
172
173 # The "runInTerminal" request sent by the adapter to spawn the launcher,
174 # if any, shouldn't be using sudo.
175 assert all(
176 "sudo" not in req.arguments["args"]
177 for req in session.all_occurrences_of(timeline.Request("runInTerminal"))
178 )
179
180 # The launcher, however, should use our dummy sudo to spawn the debuggee,
181 # and the debuggee should report the environment variable accordingly.
182 assert backchannel.receive() == "1"
183
184
185def make_custompy(tmpdir, id=""):

Callers

nothing calls this directly

Calls 7

allFunction · 0.85
open_backchannelMethod · 0.80
receiveMethod · 0.80
runFunction · 0.70
targetFunction · 0.70
writeMethod · 0.45
all_occurrences_ofMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…