Skip to content

Commit

Permalink
Ignore the extension's Python files when debugging. (#5103)
Browse files Browse the repository at this point in the history
(for #3201)
  • Loading branch information
ericsnowcurrently committed Apr 8, 2019
1 parent a0d8d77 commit bd9805a
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .github/test_plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ class FailingTests(unittest.TestCase):
- [ ] `Run Test` works
- [ ] `Debug Test` works
- [ ] Module/suite setup methods are also run (run the `test_setup` method to verify)
- [ ] while debugging tests, an uncaught exception in a test does not
cause ptvsd to raise SystemExit

#### [`pytest`](https://code.visualstudio.com/docs/python/unit-testing#_pytest-configuration-settings)
```python
Expand Down
1 change: 1 addition & 0 deletions news/2 Fixes/3201.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ignore the extension's Python files when debugging.
2 changes: 0 additions & 2 deletions pythonFiles/ptvsd_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
sys.path.insert(0, ptvs_lib_path)
try:
import ptvsd
import ptvsd.debugger as vspd
from ptvsd.__main__ import main
ptvsd_loaded = True
except ImportError:
ptvsd_loaded = False
raise
vspd.DONT_DEBUG.append(os.path.normcase(__file__))
except:
traceback.print_exc()
print('''
Expand Down
2 changes: 0 additions & 2 deletions pythonFiles/testlauncher.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ def exclude_current_file_from_debugger():
# Load the debugger package
try:
import ptvsd
import ptvsd.debugger as vspd
vspd.DONT_DEBUG.append(os.path.normcase(__file__))
except:
traceback.print_exc()
print('''
Expand Down
4 changes: 2 additions & 2 deletions pythonFiles/visualstudio_py_testlauncher.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def main():
(opts, _) = parser.parse_args()

if opts.debug:
from ptvsd.visualstudio_py_debugger import DONT_DEBUG, DEBUG_ENTRYPOINTS, get_code
from ptvsd.visualstudio_py_debugger import DEBUG_ENTRYPOINTS, get_code

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

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

pass
Expand Down
7 changes: 7 additions & 0 deletions src/client/unittests/common/debugLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ export class DebugLauncher implements ITestDebugLauncher {
request: 'test'
};
}
if (!debugConfig.rules) {
debugConfig.rules = [];
}
debugConfig.rules.push({
path: path.join(EXTENSION_ROOT_DIR, 'pythonFiles'),
include: false
});
this.applyDefaults(debugConfig!, workspaceFolder, configSettings);

return this.convertConfigToArgs(debugConfig!, workspaceFolder, options);
Expand Down
9 changes: 6 additions & 3 deletions src/test/providers/foldingProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ suite('Provider - Folding Provider', () => {
const docStringFileAndExpectedFoldingRanges: FileFoldingRanges[] = [
{
file: path.join(pythonFilesPath, 'attach_server.py'), ranges: [
new FoldingRange(0, 14), new FoldingRange(44, 73, FoldingRangeKind.Comment),
new FoldingRange(95, 143), new FoldingRange(149, 150, FoldingRangeKind.Comment),
new FoldingRange(305, 313), new FoldingRange(320, 322)
new FoldingRange(0, 14),
new FoldingRange(44, 73, FoldingRangeKind.Comment),
new FoldingRange(98, 146),
new FoldingRange(152, 153, FoldingRangeKind.Comment),
new FoldingRange(312, 320),
new FoldingRange(327, 329)
]
},
{
Expand Down
9 changes: 8 additions & 1 deletion src/test/pythonFiles/folding/attach_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@
ATCH = to_bytes('ATCH')
REPL = to_bytes('REPL')

PY_ROOT = os.path.normcase(__file__)
while os.path.basename(PY_ROOT) != 'pythonFiles':
PY_ROOT = os.path.dirname(PY_ROOT)

_attach_enabled = False
_attached = threading.Event()
vspd.DONT_DEBUG.append(os.path.normcase(__file__))


class AttachAlreadyEnabledError(Exception):
Expand Down Expand Up @@ -238,6 +241,10 @@ def server_thread_func():

elif response == ATCH:
debug_options = vspd.parse_debug_options(read_string(client))
debug_options.setdefault('rules', []).append({
'path': PY_ROOT,
'include': False,
})
if redirect_output:
debug_options.add('RedirectOutput')

Expand Down
9 changes: 8 additions & 1 deletion src/test/pythonFiles/folding/noComments.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@
ATCH = to_bytes('ATCH')
REPL = to_bytes('REPL')

PY_ROOT = os.path.normcase(__file__)
while os.path.basename(PY_ROOT) != 'pythonFiles':
PY_ROOT = os.path.dirname(PY_ROOT)

_attach_enabled = False
_attached = threading.Event()
vspd.DONT_DEBUG.append(os.path.normcase(__file__))


class AttachAlreadyEnabledError(Exception):
Expand Down Expand Up @@ -187,6 +190,10 @@ def server_thread_func():

elif response == ATCH:
debug_options = vspd.parse_debug_options(read_string(client))
debug_options.setdefault('rules', []).append({
'path': PY_ROOT,
'include': False,
})
if redirect_output:
debug_options.add('RedirectOutput')

Expand Down
9 changes: 8 additions & 1 deletion src/test/pythonFiles/folding/noDocStrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@
ATCH = to_bytes('ATCH')
REPL = to_bytes('REPL')

PY_ROOT = os.path.normcase(__file__)
while os.path.basename(PY_ROOT) != 'pythonFiles':
PY_ROOT = os.path.dirname(PY_ROOT)

_attach_enabled = False
_attached = threading.Event()
vspd.DONT_DEBUG.append(os.path.normcase(__file__))


class AttachAlreadyEnabledError(Exception):
Expand Down Expand Up @@ -187,6 +190,10 @@ def server_thread_func():

elif response == ATCH:
debug_options = vspd.parse_debug_options(read_string(client))
debug_options.setdefault('rules', []).append({
'path': PY_ROOT,
'include': False,
})
if redirect_output:
debug_options.add('RedirectOutput')

Expand Down
9 changes: 8 additions & 1 deletion src/test/pythonFiles/folding/visualstudio_py_repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@

DEBUG = os.environ.get('DEBUG_REPL') is not None

PY_ROOT = os.path.normcase(__file__)
while os.path.basename(PY_ROOT) != 'pythonFiles':
PY_ROOT = os.path.dirname(PY_ROOT)

__all__ = ['ReplBackend', 'BasicReplBackend', 'BACKEND']

def _debug_write(out):
Expand Down Expand Up @@ -349,6 +353,10 @@ def _cmd_debug_attach(self):
port = read_int(self.conn)
id = read_string(self.conn)
debug_options = visualstudio_py_debugger.parse_debug_options(read_string(self.conn))
debug_options.setdefault('rules', []).append({
'path': PY_ROOT,
'include': False,
})
self.attach_process(port, id, debug_options)

_COMMANDS = {
Expand Down Expand Up @@ -380,7 +388,6 @@ def init_debugger(self):
from os import path
sys.path.append(path.dirname(__file__))
import visualstudio_py_debugger
visualstudio_py_debugger.DONT_DEBUG.append(path.normcase(__file__))
new_thread = visualstudio_py_debugger.new_thread()
sys.settrace(new_thread.trace_func)
visualstudio_py_debugger.intercept_threads(True)
Expand Down
3 changes: 3 additions & 0 deletions src/test/unittests/common/debugLauncher.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ suite('Unit Tests - Debug Launcher', () => {
if (!expected) {
expected = getDefaultDebugConfig();
}
expected.rules = [
{ path: path.join(EXTENSION_ROOT_DIR, 'pythonFiles'), include: false }
];
expected.program = testLaunchScript;
expected.args = options.args;
if (!expected.cwd) {
Expand Down

0 comments on commit bd9805a

Please sign in to comment.