mirror of
https://github.com/microsoft/debugpy.git
synced 2025-12-23 08:48:12 +00:00
Expose CLI Options through public API (#1928)
* Expose CLI Options through public API Expose a public API that can retrieve the processed CLI options for the current process launched through the debugpy CLI. This enables code to be able to retrieve options like the port and adapter access token to be used for launching their own child process' that can be debugged. * Fix test by sending dict not dataclass object
This commit is contained in:
parent
ead90f6f71
commit
1aff9aa541
5 changed files with 97 additions and 7 deletions
35
tests/debugpy/test_cli_args.py
Normal file
35
tests/debugpy/test_cli_args.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License. See LICENSE in the project root
|
||||
# for license information.
|
||||
|
||||
from tests import debug
|
||||
|
||||
|
||||
def test_cli_options_with_no_debugger():
|
||||
import debugpy
|
||||
|
||||
cli_options = debugpy.get_cli_options()
|
||||
assert cli_options is None
|
||||
|
||||
|
||||
def test_cli_options_under_file_connect(pyfile, target, run):
|
||||
@pyfile
|
||||
def code_to_debug():
|
||||
import dataclasses
|
||||
import debugpy
|
||||
|
||||
import debuggee
|
||||
from debuggee import backchannel
|
||||
|
||||
debuggee.setup()
|
||||
backchannel.send(dataclasses.asdict(debugpy.get_cli_options()))
|
||||
|
||||
with debug.Session() as session:
|
||||
backchannel = session.open_backchannel()
|
||||
|
||||
with run(session, target(code_to_debug)):
|
||||
pass
|
||||
|
||||
cli_options = backchannel.receive()
|
||||
assert cli_options['mode'] == 'connect'
|
||||
assert cli_options['target_kind'] == 'file'
|
||||
|
|
@ -630,7 +630,7 @@ def test_subprocess_with_parent_pid(pyfile, target, run):
|
|||
import subprocess
|
||||
import sys
|
||||
|
||||
from debugpy.server import cli as debugpy_cli
|
||||
import debugpy
|
||||
|
||||
debuggee.setup()
|
||||
|
||||
|
|
@ -642,8 +642,11 @@ def test_subprocess_with_parent_pid(pyfile, target, run):
|
|||
else:
|
||||
argv = ["/bin/sh", "-c"]
|
||||
|
||||
host, port = debugpy_cli.options.address
|
||||
access_token = debugpy_cli.options.adapter_access_token
|
||||
cli_opts = debugpy.get_cli_options()
|
||||
assert cli_opts, "No CLI options found"
|
||||
|
||||
host, port = cli_opts.address
|
||||
access_token = cli_opts.adapter_access_token
|
||||
|
||||
shell_args = [
|
||||
sys.executable,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue