Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/language-tools/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class PythonLanguageTools
}

// Document symbols provided by Pylance.
const symbols: vscode.DocumentSymbol[] =
const symbols: vscode.DocumentSymbol[] | undefined =
await vscode.commands.executeCommand(
'vscode.executeDocumentSymbolProvider',
document
Expand Down Expand Up @@ -161,8 +161,10 @@ export class PythonLanguageTools
}

// Start at top level and evaluate each symbol in the document.
for (const symbol of symbols) {
evaluateCurrentSymbol(symbol)
if (symbols) {
for (const symbol of symbols) {
evaluateCurrentSymbol(symbol)
}
}

const finalTestCases = result.filter(item => {
Expand Down
10 changes: 10 additions & 0 deletions src/test/suite/language-tools/python.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ suite('Python Language Tools', () => {
assert.equal(result.documentTest?.name, 'my_test.py')
})

test('undefined symbols', async () => {
executeCommandStub.resolves(undefined)
const result = await languageTools.getDocumentTestCases(
vscode.Uri.parse('file:///repo/root/sample/my_test.py'),
'/repo/root/'
)
assert.strictEqual(result.isTestFile, true)
assert.strictEqual(result.testCases.length, 0)
})

test('non test file', async () => {
const result = await languageTools.getDocumentTestCases(
vscode.Uri.parse('file:///repo/root/sample/my_file.py'),
Expand Down