mirror of
https://github.com/microsoft/debugpy.git
synced 2025-12-23 08:48:12 +00:00
Fix #93: null values not supported in "env"
This commit is contained in:
parent
1727a3e109
commit
5384d23743
2 changed files with 22 additions and 9 deletions
|
|
@ -78,7 +78,7 @@ def launch_request(request):
|
|||
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
|
||||
|
|
@ -94,6 +94,7 @@ def launch_request(request):
|
|||
# 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"
|
||||
|
|
|
|||
|
|
@ -12,9 +12,10 @@ from tests import debug
|
|||
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
|
||||
|
|
@ -29,25 +30,36 @@ def test_env_replace_var(pyfile, target, run, case):
|
|||
|
||||
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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue