Skip to content

Commit

Permalink
When debugging unit tests, use the envFile in settings (#1825)
Browse files Browse the repository at this point in the history
Fixes #1759
  • Loading branch information
DonJayamanne committed Jun 5, 2018
1 parent 74d8210 commit 72789f6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions news/2 Fixes/1759.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When debugging unit tests, use the `env` file configured in `settings.json` under `python.envFile`.
6 changes: 3 additions & 3 deletions src/client/unittests/common/debugLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ export class DebugLauncher implements ITestDebugLauncher {
}

const cwd = cwdUri ? cwdUri.fsPath : workspaceFolder.uri.fsPath;
const configurationService = this.serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings(Uri.file(cwd));
const useExperimentalDebugger = configurationService.unitTest.useExperimentalDebugger === true;
const configSettings = this.serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings(Uri.file(cwd));
const useExperimentalDebugger = configSettings.unitTest.useExperimentalDebugger === true;
const debugManager = this.serviceContainer.get<IDebugService>(IDebugService);
const debuggerType = useExperimentalDebugger ? 'pythonExperimental' : 'python';
const debugArgs = this.fixArgs(options.args, options.testProvider, useExperimentalDebugger);
const program = this.getTestLauncherScript(options.testProvider, useExperimentalDebugger);

return debugManager.startDebugging(workspaceFolder, {
name: 'Debug Unit Test',
type: debuggerType,
Expand All @@ -41,6 +40,7 @@ export class DebugLauncher implements ITestDebugLauncher {
cwd,
args: debugArgs,
console: 'none',
envFile: configSettings.envFile,
debugOptions: [DebugOptions.RedirectOutput]
}).then(() => void (0));
}
Expand Down
7 changes: 5 additions & 2 deletions src/test/unittests/common/debugLauncher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ suite('Unit Tests - Debug Launcher', () => {
let debugLauncher: DebugLauncher;
let debugService: TypeMoq.IMock<IDebugService>;
let workspaceService: TypeMoq.IMock<IWorkspaceService>;
let settings: TypeMoq.IMock<IPythonSettings>;
setup(async () => {
const serviceContainer = TypeMoq.Mock.ofType<IServiceContainer>();
const configService = TypeMoq.Mock.ofType<IConfigurationService>();
Expand All @@ -38,7 +39,7 @@ suite('Unit Tests - Debug Launcher', () => {
workspaceService = TypeMoq.Mock.ofType<IWorkspaceService>();
serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IWorkspaceService))).returns(() => workspaceService.object);

const settings = TypeMoq.Mock.ofType<IPythonSettings>();
settings = TypeMoq.Mock.ofType<IPythonSettings>();
configService.setup(c => c.getSettings(TypeMoq.It.isAny())).returns(() => settings.object);

unitTestSettings = TypeMoq.Mock.ofType<IUnitTestSettings>();
Expand All @@ -51,10 +52,12 @@ suite('Unit Tests - Debug Launcher', () => {
args: string[], console, debugOptions: DebugOptions[],
testProvider: TestProvider, useExperimentalDebugger: boolean) {

const envFile = __filename;
settings.setup(p => p.envFile).returns(() => envFile);
const debugArgs = testProvider === 'unittest' && useExperimentalDebugger ? args.filter(item => item !== '--debug') : args;

debugService.setup(d => d.startDebugging(TypeMoq.It.isValue(workspaceFolder),
TypeMoq.It.isObjectWith({ name, type, request, program, cwd, args: debugArgs, console, debugOptions })))
TypeMoq.It.isObjectWith({ name, type, request, program, cwd, args: debugArgs, console, envFile, debugOptions })))
.returns(() => Promise.resolve(undefined as any))
.verifiable(TypeMoq.Times.once());
}
Expand Down

0 comments on commit 72789f6

Please sign in to comment.