Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/debugpy/server/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ def parse_args_helper(
raise ValueError("duplicate switch from environment: " + switch)
# if we're parsing from the environment, and we've already seen the switch on the command line, skip it, since command line takes precedence
elif isFromEnvironment and switch in seenFromCommandLine:
# also skip the switch's value, if any, so it isn't parsed as a switch or target
if switch and placeholder is not None:
next(iterator, None)
continue
# otherwise, the switch is new, so add it to the appropriate set
else:
Expand Down
13 changes: 13 additions & 0 deletions tests/debugpy/server/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,19 @@ def test_override_environment_switch(cli):
assert options["address"] == ("127.0.0.1", 8888)
assert options["target"] == "spam.py"


# Test that the value of an overridden environment switch is skipped along with it
def test_override_environment_switch_with_module_target(cli):
args = ["--connect", "8888", "-m", "spam"]

with mock.patch.dict(os.environ, {"DEBUGPY_EXTRA_ARGV": "--connect 5678"}):
_, options = cli(args)

assert options["address"] == ("127.0.0.1", 8888)
assert options["target_kind"] == "module"
assert options["target"] == "spam"


# Test that script args (passed to target) are preserved
def test_script_args(cli):
args = ["--listen", "8888", "spam.py", "arg1", "arg2"]
Expand Down
Loading