Skip to content

Commit

Permalink
Introduce autoTestDiscoverOnSavePattern test configuration option
Browse files Browse the repository at this point in the history
  • Loading branch information
soceanainn committed Jan 17, 2025
1 parent 8c54b8a commit c61bbd7
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,12 @@
"scope": "resource",
"type": "boolean"
},
"python.testing.autoTestDiscoverOnSavePattern": {
"default": "**.py",
"description": "%python.testing.autoTestDiscoverOnSavePattern.description%",
"scope": "resource",
"type": "string"
},
"python.testing.cwd": {
"default": null,
"description": "%python.testing.cwd.description%",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"python.terminal.focusAfterLaunch.description": "When launching a python terminal, whether to focus the cursor on the terminal.",
"python.terminal.launchArgs.description": "Python launch arguments to use when executing a file in the terminal.",
"python.testing.autoTestDiscoverOnSaveEnabled.description": "Enable auto run test discovery when saving a test file.",
"python.testing.autoTestDiscoverOnSavePattern.description": "Glob pattern used to determine which files are used by autoTestDiscoverOnSaveEnabled.",
"python.testing.cwd.description": "Optional working directory for tests.",
"python.testing.debugPort.description": "Port number used for debugging of tests.",
"python.testing.promptToConfigure.description": "Prompt to configure a test framework if potential tests directories are discovered.",
Expand Down
3 changes: 2 additions & 1 deletion resources/report_issue_user_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
"pytestPath": "placeholder",
"unittestArgs": "placeholder",
"unittestEnabled": true,
"autoTestDiscoverOnSaveEnabled": true
"autoTestDiscoverOnSaveEnabled": true,
"autoTestDiscoverOnSavePattern": "placeholder"
},
"terminal": {
"activateEnvironment": true,
Expand Down
2 changes: 2 additions & 0 deletions src/client/common/configSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ export class PythonSettings implements IPythonSettings {
unittestEnabled: false,
pytestPath: 'pytest',
autoTestDiscoverOnSaveEnabled: true,
autoTestDiscoverOnSavePattern: "**"
} as ITestingSettings;
}
}
Expand All @@ -336,6 +337,7 @@ export class PythonSettings implements IPythonSettings {
unittestArgs: [],
unittestEnabled: false,
autoTestDiscoverOnSaveEnabled: true,
autoTestDiscoverOnSavePattern: "**",
};
this.testing.pytestPath = getAbsolutePath(systemVariables.resolveAny(this.testing.pytestPath), workspaceRoot);
if (this.testing.cwd) {
Expand Down
1 change: 1 addition & 0 deletions src/client/testing/configuration/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface ITestingSettings {
unittestArgs: string[];
cwd?: string;
readonly autoTestDiscoverOnSaveEnabled: boolean;
readonly autoTestDiscoverOnSavePattern: string;
}

export type TestSettingsPropertyNames = {
Expand Down
7 changes: 4 additions & 3 deletions src/client/testing/testController/controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import * as minimatch from 'minimatch';
import { inject, injectable, named } from 'inversify';
import { uniq } from 'lodash';
import {
Expand Down Expand Up @@ -215,7 +216,7 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
if (settings.testing.autoTestDiscoverOnSaveEnabled) {
traceVerbose(`Testing: Setting up watcher for ${workspace.uri.fsPath}`);
this.watchForSettingsChanges(workspace);
this.watchForTestContentChangeOnSave();
this.watchForTestContentChangeOnSave(settings.testing.autoTestDiscoverOnSavePattern);
}
});
}
Expand Down Expand Up @@ -549,10 +550,10 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
);
}

private watchForTestContentChangeOnSave(): void {
private watchForTestContentChangeOnSave(testFileGlob: String): void {
this.disposables.push(
onDidSaveTextDocument(async (doc: TextDocument) => {
if (doc.fileName.endsWith('.py')) {
if (minimatch.default(doc.uri.fs, testFileGlob)) {
traceVerbose(`Testing: Trigger refresh after saving ${doc.uri.fsPath}`);
this.sendTriggerTelemetry('watching');
this.refreshData.trigger(doc.uri, false);
Expand Down

0 comments on commit c61bbd7

Please sign in to comment.