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

Function test_env_replace_var

tests/debugpy/test_env.py:16–65  ·  view source on GitHub ↗
(pyfile, target, run, case, new_value)

Source from the content-addressed store, hash-verified

14@pytest.mark.parametrize("case", ["match_case", "mismatch_case"])
15@pytest.mark.parametrize("run", runners.all_launch)
16def test_env_replace_var(pyfile, target, run, case, new_value):
17 @pyfile
18 def code_to_debug():
19 import os
20
21 import debuggee
22 from debuggee import backchannel
23
24 debuggee.setup()
25 backchannel.send(dict(os.environ))
26
27 varname = "DEBUGPY_DUMMY_ENV_VAR"
28
29 with debug.Session() as session:
30 backchannel = session.open_backchannel()
31 session.config.env[
32 varname if case == "match_case" else varname.lower()
33 ] = new_value
34
35 os.environ[varname] = "1"
36 try:
37 with run(session, target(code_to_debug)):
38 pass
39 finally:
40 del os.environ[varname]
41
42 env = backchannel.receive()
43 if case == "match_case":
44 # If case matches, debug config should replace global env var regardless
45 # of the platform.
46 if new_value is None:
47 assert varname not in env
48 else:
49 assert env[varname] == "42"
50 elif sys.platform == "win32":
51 # On Win32, variable names are case-insensitive, so debug config should
52 # replace the global env var even if there is a case mismatch.
53 if new_value is None:
54 assert varname not in env
55 else:
56 assert env[varname] == "42"
57 assert varname.lower() not in env
58 else:
59 # On other platforms, variable names are case-sensitive, so case mismatch
60 # should result in two different variables.
61 assert env[varname] == "1"
62 if new_value is None:
63 assert varname.lower() not in env
64 else:
65 assert env[varname.lower()] == "42"

Callers

nothing calls this directly

Calls 4

open_backchannelMethod · 0.80
receiveMethod · 0.80
runFunction · 0.70
targetFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…