Skip to content

Commit bd9805a

Browse files
Ignore the extension's Python files when debugging. (#5103)
(for #3201)
1 parent a0d8d77 commit bd9805a

File tree

12 files changed

+53
-13
lines changed

12 files changed

+53
-13
lines changed

.github/test_plan.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ class FailingTests(unittest.TestCase):
297297
- [ ] `Run Test` works
298298
- [ ] `Debug Test` works
299299
- [ ] Module/suite setup methods are also run (run the `test_setup` method to verify)
300+
- [ ] while debugging tests, an uncaught exception in a test does not
301+
cause ptvsd to raise SystemExit
300302

301303
#### [`pytest`](https://code.visualstudio.com/docs/python/unit-testing#_pytest-configuration-settings)
302304
```python

news/2 Fixes/3201.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ignore the extension's Python files when debugging.

pythonFiles/ptvsd_launcher.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@
1919
sys.path.insert(0, ptvs_lib_path)
2020
try:
2121
import ptvsd
22-
import ptvsd.debugger as vspd
2322
from ptvsd.__main__ import main
2423
ptvsd_loaded = True
2524
except ImportError:
2625
ptvsd_loaded = False
2726
raise
28-
vspd.DONT_DEBUG.append(os.path.normcase(__file__))
2927
except:
3028
traceback.print_exc()
3129
print('''

pythonFiles/testlauncher.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ def exclude_current_file_from_debugger():
2020
# Load the debugger package
2121
try:
2222
import ptvsd
23-
import ptvsd.debugger as vspd
24-
vspd.DONT_DEBUG.append(os.path.normcase(__file__))
2523
except:
2624
traceback.print_exc()
2725
print('''

pythonFiles/visualstudio_py_testlauncher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def main():
222222
(opts, _) = parser.parse_args()
223223

224224
if opts.debug:
225-
from ptvsd.visualstudio_py_debugger import DONT_DEBUG, DEBUG_ENTRYPOINTS, get_code
225+
from ptvsd.visualstudio_py_debugger import DEBUG_ENTRYPOINTS, get_code
226226

227227
sys.path[0] = os.getcwd()
228228
if opts.result_port:
@@ -238,7 +238,7 @@ def main():
238238
sys.stderr = _TestOutput(sys.stderr, is_stdout = False)
239239

240240
if opts.debug:
241-
DONT_DEBUG.append(os.path.normcase(__file__))
241+
# TODO: Stop using this internal API? (See #3201.)
242242
DEBUG_ENTRYPOINTS.add(get_code(main))
243243

244244
pass

src/client/unittests/common/debugLauncher.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ export class DebugLauncher implements ITestDebugLauncher {
7272
request: 'test'
7373
};
7474
}
75+
if (!debugConfig.rules) {
76+
debugConfig.rules = [];
77+
}
78+
debugConfig.rules.push({
79+
path: path.join(EXTENSION_ROOT_DIR, 'pythonFiles'),
80+
include: false
81+
});
7582
this.applyDefaults(debugConfig!, workspaceFolder, configSettings);
7683

7784
return this.convertConfigToArgs(debugConfig!, workspaceFolder, options);

src/test/providers/foldingProvider.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ suite('Provider - Folding Provider', () => {
1414
const docStringFileAndExpectedFoldingRanges: FileFoldingRanges[] = [
1515
{
1616
file: path.join(pythonFilesPath, 'attach_server.py'), ranges: [
17-
new FoldingRange(0, 14), new FoldingRange(44, 73, FoldingRangeKind.Comment),
18-
new FoldingRange(95, 143), new FoldingRange(149, 150, FoldingRangeKind.Comment),
19-
new FoldingRange(305, 313), new FoldingRange(320, 322)
17+
new FoldingRange(0, 14),
18+
new FoldingRange(44, 73, FoldingRangeKind.Comment),
19+
new FoldingRange(98, 146),
20+
new FoldingRange(152, 153, FoldingRangeKind.Comment),
21+
new FoldingRange(312, 320),
22+
new FoldingRange(327, 329)
2023
]
2124
},
2225
{

src/test/pythonFiles/folding/attach_server.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,12 @@
8383
ATCH = to_bytes('ATCH')
8484
REPL = to_bytes('REPL')
8585

86+
PY_ROOT = os.path.normcase(__file__)
87+
while os.path.basename(PY_ROOT) != 'pythonFiles':
88+
PY_ROOT = os.path.dirname(PY_ROOT)
89+
8690
_attach_enabled = False
8791
_attached = threading.Event()
88-
vspd.DONT_DEBUG.append(os.path.normcase(__file__))
8992

9093

9194
class AttachAlreadyEnabledError(Exception):
@@ -238,6 +241,10 @@ def server_thread_func():
238241

239242
elif response == ATCH:
240243
debug_options = vspd.parse_debug_options(read_string(client))
244+
debug_options.setdefault('rules', []).append({
245+
'path': PY_ROOT,
246+
'include': False,
247+
})
241248
if redirect_output:
242249
debug_options.add('RedirectOutput')
243250

src/test/pythonFiles/folding/noComments.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@
3535
ATCH = to_bytes('ATCH')
3636
REPL = to_bytes('REPL')
3737

38+
PY_ROOT = os.path.normcase(__file__)
39+
while os.path.basename(PY_ROOT) != 'pythonFiles':
40+
PY_ROOT = os.path.dirname(PY_ROOT)
41+
3842
_attach_enabled = False
3943
_attached = threading.Event()
40-
vspd.DONT_DEBUG.append(os.path.normcase(__file__))
4144

4245

4346
class AttachAlreadyEnabledError(Exception):
@@ -187,6 +190,10 @@ def server_thread_func():
187190

188191
elif response == ATCH:
189192
debug_options = vspd.parse_debug_options(read_string(client))
193+
debug_options.setdefault('rules', []).append({
194+
'path': PY_ROOT,
195+
'include': False,
196+
})
190197
if redirect_output:
191198
debug_options.add('RedirectOutput')
192199

src/test/pythonFiles/folding/noDocStrings.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,12 @@
8383
ATCH = to_bytes('ATCH')
8484
REPL = to_bytes('REPL')
8585

86+
PY_ROOT = os.path.normcase(__file__)
87+
while os.path.basename(PY_ROOT) != 'pythonFiles':
88+
PY_ROOT = os.path.dirname(PY_ROOT)
89+
8690
_attach_enabled = False
8791
_attached = threading.Event()
88-
vspd.DONT_DEBUG.append(os.path.normcase(__file__))
8992

9093

9194
class AttachAlreadyEnabledError(Exception):
@@ -187,6 +190,10 @@ def server_thread_func():
187190

188191
elif response == ATCH:
189192
debug_options = vspd.parse_debug_options(read_string(client))
193+
debug_options.setdefault('rules', []).append({
194+
'path': PY_ROOT,
195+
'include': False,
196+
})
190197
if redirect_output:
191198
debug_options.add('RedirectOutput')
192199

0 commit comments

Comments
 (0)