Skip to content

Commit

Permalink
Add setting for auto run test discover on save (#1687)
Browse files Browse the repository at this point in the history
  • Loading branch information
lingyv-li authored and DonJayamanne committed Jun 7, 2018
1 parent b1055e1 commit a5483db
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions news/1 Enhancements/1037.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add setting for auto run test discover on save
(thanks [Lingyu Li](http://github.com/lingyv-li/))
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,12 @@
"description": "Use the experimental debugger when debugging unit tests.",
"scope": "resource"
},
"python.unitTest.autoTestDiscoverOnSaveEnabled": {
"type": "boolean",
"default": true,
"description": "Whether to enable or disable auto run test discovery when saving a unit test file.",
"scope": "resource"
},
"python.venvFolders": {
"type": "array",
"default": [
Expand Down
4 changes: 2 additions & 2 deletions src/client/common/configSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
nosetestArgs: [], pyTestArgs: [], unittestArgs: [],
promptToConfigure: true, debugPort: 3000,
nosetestsEnabled: false, pyTestEnabled: false, unittestEnabled: false,
nosetestPath: 'nosetests', pyTestPath: 'pytest'
nosetestPath: 'nosetests', pyTestPath: 'pytest', autoTestDiscoverOnSaveEnabled: true
} as IUnitTestSettings;
}
}
Expand All @@ -278,7 +278,7 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
debugPort: 3000,
nosetestArgs: [], nosetestPath: 'nosetest', nosetestsEnabled: false,
pyTestArgs: [], pyTestEnabled: false, pyTestPath: 'pytest',
unittestArgs: [], unittestEnabled: false
unittestArgs: [], unittestEnabled: false, autoTestDiscoverOnSaveEnabled: true
};
this.unitTest.pyTestPath = getAbsolutePath(systemVariables.resolveAny(this.unitTest.pyTestPath), workspaceRoot);
this.unitTest.nosetestPath = getAbsolutePath(systemVariables.resolveAny(this.unitTest.nosetestPath), workspaceRoot);
Expand Down
1 change: 1 addition & 0 deletions src/client/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export interface IUnitTestSettings {
unittestArgs: string[];
cwd?: string;
readonly useExperimentalDebugger?: boolean;
readonly autoTestDiscoverOnSaveEnabled: boolean;
}
export interface IPylintCategorySeverity {
readonly convention: DiagnosticSeverity;
Expand Down
9 changes: 8 additions & 1 deletion src/client/unittests/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,17 @@ export class UnitTestManagementService implements IUnitTestManagementService, Di

disposablesRegistry.push(...disposables);
}
private onDocumentSaved(doc: TextDocument) {
const settings = this.serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings(doc.uri);
if (!settings.unitTest.autoTestDiscoverOnSaveEnabled) {
return;
}
this.discoverTestsForDocument(doc);
}
private registerHandlers() {
const documentManager = this.serviceContainer.get<IDocumentManager>(IDocumentManager);

this.disposableRegistry.push(documentManager.onDidSaveTextDocument(this.discoverTestsForDocument.bind(this)));
this.disposableRegistry.push(documentManager.onDidSaveTextDocument(this.onDocumentSaved.bind(this)));
this.disposableRegistry.push(this.workspaceService.onDidChangeConfiguration(e => {
if (this.configChangedTimer) {
clearTimeout(this.configChangedTimer);
Expand Down

0 comments on commit a5483db

Please sign in to comment.