Skip to content

Commit a5483db

Browse files
lingyv-liDonJayamanne
authored andcommitted
Add setting for auto run test discover on save (microsoft#1687)
1 parent b1055e1 commit a5483db

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

news/1 Enhancements/1037.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add setting for auto run test discover on save
2+
(thanks [Lingyu Li](http://github.com/lingyv-li/))

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,12 @@
17221722
"description": "Use the experimental debugger when debugging unit tests.",
17231723
"scope": "resource"
17241724
},
1725+
"python.unitTest.autoTestDiscoverOnSaveEnabled": {
1726+
"type": "boolean",
1727+
"default": true,
1728+
"description": "Whether to enable or disable auto run test discovery when saving a unit test file.",
1729+
"scope": "resource"
1730+
},
17251731
"python.venvFolders": {
17261732
"type": "array",
17271733
"default": [

src/client/common/configSettings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
267267
nosetestArgs: [], pyTestArgs: [], unittestArgs: [],
268268
promptToConfigure: true, debugPort: 3000,
269269
nosetestsEnabled: false, pyTestEnabled: false, unittestEnabled: false,
270-
nosetestPath: 'nosetests', pyTestPath: 'pytest'
270+
nosetestPath: 'nosetests', pyTestPath: 'pytest', autoTestDiscoverOnSaveEnabled: true
271271
} as IUnitTestSettings;
272272
}
273273
}
@@ -278,7 +278,7 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
278278
debugPort: 3000,
279279
nosetestArgs: [], nosetestPath: 'nosetest', nosetestsEnabled: false,
280280
pyTestArgs: [], pyTestEnabled: false, pyTestPath: 'pytest',
281-
unittestArgs: [], unittestEnabled: false
281+
unittestArgs: [], unittestEnabled: false, autoTestDiscoverOnSaveEnabled: true
282282
};
283283
this.unitTest.pyTestPath = getAbsolutePath(systemVariables.resolveAny(this.unitTest.pyTestPath), workspaceRoot);
284284
this.unitTest.nosetestPath = getAbsolutePath(systemVariables.resolveAny(this.unitTest.nosetestPath), workspaceRoot);

src/client/common/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export interface IUnitTestSettings {
137137
unittestArgs: string[];
138138
cwd?: string;
139139
readonly useExperimentalDebugger?: boolean;
140+
readonly autoTestDiscoverOnSaveEnabled: boolean;
140141
}
141142
export interface IPylintCategorySeverity {
142143
readonly convention: DiagnosticSeverity;

src/client/unittests/main.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,17 @@ export class UnitTestManagementService implements IUnitTestManagementService, Di
308308

309309
disposablesRegistry.push(...disposables);
310310
}
311+
private onDocumentSaved(doc: TextDocument) {
312+
const settings = this.serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings(doc.uri);
313+
if (!settings.unitTest.autoTestDiscoverOnSaveEnabled) {
314+
return;
315+
}
316+
this.discoverTestsForDocument(doc);
317+
}
311318
private registerHandlers() {
312319
const documentManager = this.serviceContainer.get<IDocumentManager>(IDocumentManager);
313320

314-
this.disposableRegistry.push(documentManager.onDidSaveTextDocument(this.discoverTestsForDocument.bind(this)));
321+
this.disposableRegistry.push(documentManager.onDidSaveTextDocument(this.onDocumentSaved.bind(this)));
315322
this.disposableRegistry.push(this.workspaceService.onDidChangeConfiguration(e => {
316323
if (this.configChangedTimer) {
317324
clearTimeout(this.configChangedTimer);

0 commit comments

Comments
 (0)