Skip to content

Commit

Permalink
Fix #93: null values not supported in "env"
Browse files Browse the repository at this point in the history
  • Loading branch information
int19h committed Oct 26, 2020
1 parent 1727a3e commit 5384d23
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/debugpy/launcher/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def property_or_debug_option(prop_name, flag_name):
process_name = request("processName", compat.filename(sys.executable))

env = os.environ.copy()
env_changes = request("env", json.object(unicode))
env_changes = request("env", json.object((unicode, type(None))))
if sys.platform == "win32":
# Environment variables are case-insensitive on Win32, so we need to normalize
# both dicts to make sure that env vars specified in the debug configuration
Expand All @@ -94,6 +94,7 @@ def property_or_debug_option(prop_name, flag_name):
# applied to the debuggee, since it will conflict with pydevd.
env.pop("COV_CORE_SOURCE", None)
env.update(env_changes)
env = {k: v for k, v in env.items() if v is not None}

if request("gevent", False):
env["GEVENT_SUPPORT"] = "True"
Expand Down
28 changes: 20 additions & 8 deletions tests/debugpy/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
from tests.debug import runners


@pytest.mark.parametrize("new_value", [None, "42"])
@pytest.mark.parametrize("case", ["match_case", "mismatch_case"])
@pytest.mark.parametrize("run", runners.all_launch)
def test_env_replace_var(pyfile, target, run, case):
def test_env_replace_var(pyfile, target, run, case, new_value):
@pyfile
def code_to_debug():
import os
Expand All @@ -29,25 +30,36 @@ def code_to_debug():

with debug.Session() as session:
backchannel = session.open_backchannel()
session.config.env[varname if case == "match_case" else varname.lower()] = "42"
session.config.env[varname if case == "match_case" else varname.lower()] = new_value

os.environ[varname] = "1"
with run(session, target(code_to_debug)):
pass
del os.environ[varname]
try:
with run(session, target(code_to_debug)):
pass
finally:
del os.environ[varname]

env = backchannel.receive()
if case == "match_case":
# If case matches, debug config should replace global env var regardless
# of the platform.
assert env[varname] == "42"
if new_value is None:
assert varname not in env
else:
assert env[varname] == "42"
elif sys.platform == "win32":
# On Win32, variable names are case-insensitive, so debug config should
# replace the global env var even if there is a case mismatch.
assert env[varname] == "42"
if new_value is None:
assert varname not in env
else:
assert env[varname] == "42"
assert varname.lower() not in env
else:
# On other platforms, variable names are case-sensitive, so case mismatch
# should result in two different variables.
assert env[varname] == "1"
assert env[varname.lower()] == "42"
if new_value is None:
assert varname.lower() not in env
else:
assert env[varname.lower()] == "42"

0 comments on commit 5384d23

Please sign in to comment.