@@ -137,44 +137,90 @@ def code_to_debug():
137
137
assert backchannel .receive () == "1"
138
138
139
139
140
- @pytest .mark .parametrize ("run" , runners .all_launch )
141
- @pytest .mark .parametrize ("python_args" , [None , "-B" ])
142
- @pytest .mark .parametrize ("python" , [None , "custompy" , "custompy,-O" ])
143
- @pytest .mark .parametrize ("python_key" , ["python" , "pythonPath" ])
144
- def test_custom_python (pyfile , tmpdir , run , target , python_key , python , python_args ):
140
+ def make_custompy (tmpdir , id = "" ):
145
141
if sys .platform == "win32" :
146
- custompy = tmpdir / "custompy.cmd"
142
+ custompy = tmpdir / ( "custompy" + id + " .cmd")
147
143
script = """@echo off
148
- set DEBUGPY_CUSTOM_PYTHON=1 %DEBUGPY_CUSTOM_PYTHON%
144
+ set DEBUGPY_CUSTOM_PYTHON=<id>; %DEBUGPY_CUSTOM_PYTHON%
149
145
<python> %*
150
146
"""
151
147
else :
152
- custompy = tmpdir / "custompy.sh"
148
+ custompy = tmpdir / ( "custompy" + id + " .sh")
153
149
script = """#!/bin/sh
154
- env DEBUGPY_CUSTOM_PYTHON=1 $DEBUGPY_CUSTOM_PYTHON <python> "$@"
150
+ env " DEBUGPY_CUSTOM_PYTHON=<id>; $DEBUGPY_CUSTOM_PYTHON" <python> "$@"
155
151
"""
156
- custompy .write (script .replace ("<python>" , sys .executable ))
152
+
153
+ script = script .replace ("<id>" , id )
154
+ script = script .replace ("<python>" , sys .executable )
155
+ custompy .write (script )
157
156
os .chmod (custompy .strpath , 0o777 )
158
157
158
+ return custompy .strpath
159
+
160
+
161
+ @pytest .mark .parametrize ("run" , runners .all_launch )
162
+ @pytest .mark .parametrize ("debuggee_custompy" , [None , "launcher" ])
163
+ @pytest .mark .parametrize ("launcher_custompy" , [None , "debuggee" ])
164
+ def test_custom_python (
165
+ pyfile , tmpdir , run , target , debuggee_custompy , launcher_custompy ,
166
+ ):
159
167
@pyfile
160
168
def code_to_debug ():
161
169
import os
170
+
171
+ import debuggee
172
+ from debuggee import backchannel
173
+
174
+ debuggee .setup ()
175
+ backchannel .send (os .getenv ("DEBUGPY_CUSTOM_PYTHON" ))
176
+
177
+ expected = ""
178
+ if debuggee_custompy :
179
+ debuggee_custompy = make_custompy (tmpdir , "debuggee" )
180
+ expected += "debuggee;"
181
+ if launcher_custompy :
182
+ launcher_custompy = make_custompy (tmpdir , "launcher" )
183
+ expected += "launcher;"
184
+ else :
185
+ # If "python" is set, it also becomes the default for "debugLauncherPython"
186
+ expected *= 2
187
+ if not len (expected ):
188
+ pytest .skip ()
189
+
190
+ with debug .Session () as session :
191
+ session .config .pop ("python" , None )
192
+ if launcher_custompy :
193
+ session .config ["debugLauncherPython" ] = launcher_custompy
194
+ if debuggee_custompy :
195
+ session .config ["python" ] = debuggee_custompy
196
+
197
+ backchannel = session .open_backchannel ()
198
+ with run (session , target (code_to_debug )):
199
+ pass
200
+
201
+ assert backchannel .receive () == expected
202
+
203
+
204
+ @pytest .mark .parametrize ("run" , runners .all_launch )
205
+ @pytest .mark .parametrize ("python_args" , [None , "-B" ])
206
+ @pytest .mark .parametrize ("python" , [None , "custompy" , "custompy,-O" ])
207
+ @pytest .mark .parametrize ("python_key" , ["python" , "pythonPath" ])
208
+ def test_custom_python_args (
209
+ pyfile , tmpdir , run , target , python_key , python , python_args
210
+ ):
211
+ @pyfile
212
+ def code_to_debug ():
162
213
import sys
163
214
164
215
import debuggee
165
216
from debuggee import backchannel
166
217
167
218
debuggee .setup ()
168
- backchannel .send (
169
- [
170
- os .getenv ("DEBUGPY_CUSTOM_PYTHON" ),
171
- sys .flags .optimize ,
172
- sys .flags .dont_write_bytecode ,
173
- ]
174
- )
219
+ backchannel .send ([sys .flags .optimize , sys .flags .dont_write_bytecode ])
175
220
221
+ custompy = make_custompy (tmpdir )
176
222
python = [] if python is None else python .split ("," )
177
- python = [(custompy . strpath if arg == "custompy" else arg ) for arg in python ]
223
+ python = [(custompy if arg == "custompy" else arg ) for arg in python ]
178
224
python_args = [] if python_args is None else python_args .split ("," )
179
225
python_cmd = (python if len (python ) else [sys .executable ]) + python_args
180
226
@@ -191,7 +237,6 @@ def code_to_debug():
191
237
pass
192
238
193
239
assert backchannel .receive () == [
194
- "11" if len (python ) else None , # one for launcher, one for debuggee
195
240
"-O" in python_cmd ,
196
241
"-B" in python_cmd ,
197
242
]
0 commit comments