Skip to content

Commit 01cb086

Browse files
author
Kartik Raj
authored
When debugging, the extension correctly uses custom .env files + Update tooltip (microsoft#4906)
* When debugging, the extension correctly uses custom .env files * Updated tests * Rename .env to .env2 * Modify tooltip * news entry for Tooltip
1 parent 66562d8 commit 01cb086

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

news/1 Enhancements/4849.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Include number of skipped tests in Test Data item tooltip

news/2 Fixes/4537.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
When debugging, the extension correctly uses custom .env files

src/client/debugger/extension/configuration/resolvers/launch.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
'use strict';
55

66
import { inject, injectable, named } from 'inversify';
7-
import * as path from 'path';
87
import { CancellationToken, Uri, WorkspaceFolder } from 'vscode';
98
import { InvalidPythonPathInDebuggerServiceId } from '../../../../application/diagnostics/checks/invalidPythonPathInDebugger';
109
import { IDiagnosticsService, IInvalidPythonPathInDebuggerService } from '../../../../application/diagnostics/types';
@@ -63,8 +62,8 @@ export class LaunchConfigurationResolver extends BaseConfigurationResolver<Launc
6362
debugConfiguration.cwd = workspaceFolder.fsPath;
6463
}
6564
if (typeof debugConfiguration.envFile !== 'string' && workspaceFolder) {
66-
const envFile = path.join(workspaceFolder.fsPath, '.env');
67-
debugConfiguration.envFile = envFile;
65+
const settings = this.configurationService.getSettings(workspaceFolder);
66+
debugConfiguration.envFile = settings.envFile;
6867
}
6968
if (typeof debugConfiguration.stopOnEntry !== 'boolean') {
7069
debugConfiguration.stopOnEntry = false;

src/client/unittests/explorer/testTreeViewItem.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ export class TestTreeItem extends TreeItem {
7979
if (result.functionsPassed === undefined) {
8080
return '';
8181
}
82+
if (result.functionsDidNotRun) {
83+
return `${result.functionsFailed} failed, ${result.functionsDidNotRun} not run and ${result.functionsPassed} passed in ${+result.time.toFixed(3)} seconds`;
84+
}
8285
return `${result.functionsFailed} failed, ${result.functionsPassed} passed in ${+result.time.toFixed(3)} seconds`;
8386
}
8487
switch (this.data.status) {

src/test/debugger/extension/configuration/resolvers/launch.unit.test.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ suite('Debugging - Config Resolver Launch', () => {
4141
folder.setup(f => f.uri).returns(() => Uri.file(folderPath));
4242
return folder.object;
4343
}
44-
function setupIoc(pythonPath: string, isWindows: boolean = false, isMac: boolean = false, isLinux: boolean = false) {
44+
function setupIoc(pythonPath: string, workspaceFolder?: WorkspaceFolder, isWindows: boolean = false, isMac: boolean = false, isLinux: boolean = false) {
4545
const confgService = TypeMoq.Mock.ofType<IConfigurationService>();
4646
workspaceService = TypeMoq.Mock.ofType<IWorkspaceService>();
4747
documentManager = TypeMoq.Mock.ofType<IDocumentManager>();
@@ -77,6 +77,9 @@ suite('Debugging - Config Resolver Launch', () => {
7777

7878
const settings = TypeMoq.Mock.ofType<IPythonSettings>();
7979
settings.setup(s => s.pythonPath).returns(() => pythonPath);
80+
if (workspaceFolder) {
81+
settings.setup(s => s.envFile).returns(() => path.join(workspaceFolder!.uri.fsPath, '.env2'));
82+
}
8083
confgService.setup(c => c.getSettings(TypeMoq.It.isAny())).returns(() => settings.object);
8184
setupOs(isWindows, isMac, isLinux);
8285

@@ -109,7 +112,7 @@ suite('Debugging - Config Resolver Launch', () => {
109112
const pythonPath = `PythonPath_${new Date().toString()}`;
110113
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
111114
const pythonFile = 'xyz.py';
112-
setupIoc(pythonPath);
115+
setupIoc(pythonPath, workspaceFolder);
113116

114117
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);
115118

@@ -123,7 +126,7 @@ suite('Debugging - Config Resolver Launch', () => {
123126
expect(debugConfig).to.have.property('cwd');
124127
expect(debugConfig!.cwd!.toLowerCase()).to.be.equal(__dirname.toLowerCase());
125128
expect(debugConfig).to.have.property('envFile');
126-
expect(debugConfig!.envFile!.toLowerCase()).to.be.equal(path.join(__dirname, '.env').toLowerCase());
129+
expect(debugConfig!.envFile!.toLowerCase()).to.be.equal(path.join(__dirname, '.env2').toLowerCase());
127130
expect(debugConfig).to.have.property('env');
128131
// tslint:disable-next-line:no-any
129132
expect(Object.keys((debugConfig as any).env)).to.have.lengthOf(0);
@@ -132,7 +135,7 @@ suite('Debugging - Config Resolver Launch', () => {
132135
const pythonPath = `PythonPath_${new Date().toString()}`;
133136
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
134137
const pythonFile = 'xyz.py';
135-
setupIoc(pythonPath);
138+
setupIoc(pythonPath, workspaceFolder);
136139
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);
137140

138141
const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, { noDebug: true } as any as DebugConfiguration);
@@ -145,15 +148,15 @@ suite('Debugging - Config Resolver Launch', () => {
145148
expect(debugConfig).to.have.property('cwd');
146149
expect(debugConfig!.cwd!.toLowerCase()).to.be.equal(__dirname.toLowerCase());
147150
expect(debugConfig).to.have.property('envFile');
148-
expect(debugConfig!.envFile!.toLowerCase()).to.be.equal(path.join(__dirname, '.env').toLowerCase());
151+
expect(debugConfig!.envFile!.toLowerCase()).to.be.equal(path.join(__dirname, '.env2').toLowerCase());
149152
expect(debugConfig).to.have.property('env');
150153
// tslint:disable-next-line:no-any
151154
expect(Object.keys((debugConfig as any).env)).to.have.lengthOf(0);
152155
});
153156
test('Defaults should be returned when an empty object is passed without Workspace Folder, no workspaces and active file', async () => {
154157
const pythonPath = `PythonPath_${new Date().toString()}`;
155158
const pythonFile = 'xyz.py';
156-
setupIoc(pythonPath);
159+
setupIoc(pythonPath, createMoqWorkspaceFolder(path.dirname(pythonFile)));
157160
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);
158161
setupWorkspaces([]);
159162

@@ -168,7 +171,7 @@ suite('Debugging - Config Resolver Launch', () => {
168171
expect(debugConfig).to.have.property('cwd');
169172
expect(debugConfig!.cwd!.toLowerCase()).to.be.equal(filePath.toLowerCase());
170173
expect(debugConfig).to.have.property('envFile');
171-
expect(debugConfig!.envFile!.toLowerCase()).to.be.equal(path.join(filePath, '.env').toLowerCase());
174+
expect(debugConfig!.envFile!.toLowerCase()).to.be.equal(path.join(filePath, '.env2').toLowerCase());
172175
expect(debugConfig).to.have.property('env');
173176
// tslint:disable-next-line:no-any
174177
expect(Object.keys((debugConfig as any).env)).to.have.lengthOf(0);
@@ -215,9 +218,9 @@ suite('Debugging - Config Resolver Launch', () => {
215218
test('Defaults should be returned when an empty object is passed without Workspace Folder, with a workspace and an active python file', async () => {
216219
const pythonPath = `PythonPath_${new Date().toString()}`;
217220
const activeFile = 'xyz.py';
218-
setupIoc(pythonPath);
219-
setupActiveEditor(activeFile, PYTHON_LANGUAGE);
220221
const defaultWorkspace = path.join('usr', 'desktop');
222+
setupIoc(pythonPath, createMoqWorkspaceFolder(defaultWorkspace));
223+
setupActiveEditor(activeFile, PYTHON_LANGUAGE);
221224
setupWorkspaces([defaultWorkspace]);
222225

223226
const debugConfig = await debugProvider.resolveDebugConfiguration!(undefined, {} as DebugConfiguration);
@@ -231,7 +234,7 @@ suite('Debugging - Config Resolver Launch', () => {
231234
expect(debugConfig).to.have.property('cwd');
232235
expect(debugConfig!.cwd!.toLowerCase()).to.be.equal(filePath.toLowerCase());
233236
expect(debugConfig).to.have.property('envFile');
234-
expect(debugConfig!.envFile!.toLowerCase()).to.be.equal(path.join(filePath, '.env').toLowerCase());
237+
expect(debugConfig!.envFile!.toLowerCase()).to.be.equal(path.join(filePath, '.env2').toLowerCase());
235238
expect(debugConfig).to.have.property('env');
236239
// tslint:disable-next-line:no-any
237240
expect(Object.keys((debugConfig as any).env)).to.have.lengthOf(0);
@@ -314,7 +317,7 @@ suite('Debugging - Config Resolver Launch', () => {
314317
const pythonPath = `PythonPath_${new Date().toString()}`;
315318
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
316319
const pythonFile = 'xyz.py';
317-
setupIoc(pythonPath, isWindows, isMac, isLinux);
320+
setupIoc(pythonPath, undefined, isWindows, isMac, isLinux);
318321
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);
319322

320323
const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, {} as DebugConfiguration);
@@ -342,7 +345,7 @@ suite('Debugging - Config Resolver Launch', () => {
342345
const workspaceFolder = createMoqWorkspaceFolder(workspacePath);
343346
const pythonFile = 'xyz.py';
344347

345-
setupIoc(pythonPath, isWindows, isMac, isLinux);
348+
setupIoc(pythonPath, undefined, isWindows, isMac, isLinux);
346349
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);
347350

348351
if (pyramidExists) {

0 commit comments

Comments
 (0)