Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a setting for disabling auto-run test discover on save #1687

Merged
merged 2 commits into from
Jun 7, 2018
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
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 @@ -1706,6 +1706,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