Skip to content

Commit b5c1b48

Browse files
committed
Introduce autoTestDiscoverOnSavePattern test configuration option
1 parent 8c54b8a commit b5c1b48

File tree

6 files changed

+16
-4
lines changed

6 files changed

+16
-4
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,12 @@
657657
"scope": "resource",
658658
"type": "boolean"
659659
},
660+
"python.testing.autoTestDiscoverOnSavePattern": {
661+
"default": "**.py",
662+
"description": "%python.testing.autoTestDiscoverOnSavePattern.description%",
663+
"scope": "resource",
664+
"type": "string"
665+
},
660666
"python.testing.cwd": {
661667
"default": null,
662668
"description": "%python.testing.cwd.description%",

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"python.terminal.focusAfterLaunch.description": "When launching a python terminal, whether to focus the cursor on the terminal.",
7575
"python.terminal.launchArgs.description": "Python launch arguments to use when executing a file in the terminal.",
7676
"python.testing.autoTestDiscoverOnSaveEnabled.description": "Enable auto run test discovery when saving a test file.",
77+
"python.testing.autoTestDiscoverOnSavePattern.description": "Glob pattern used to determine which files are used by autoTestDiscoverOnSaveEnabled.",
7778
"python.testing.cwd.description": "Optional working directory for tests.",
7879
"python.testing.debugPort.description": "Port number used for debugging of tests.",
7980
"python.testing.promptToConfigure.description": "Prompt to configure a test framework if potential tests directories are discovered.",

resources/report_issue_user_settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
"pytestPath": "placeholder",
8080
"unittestArgs": "placeholder",
8181
"unittestEnabled": true,
82-
"autoTestDiscoverOnSaveEnabled": true
82+
"autoTestDiscoverOnSaveEnabled": true,
83+
"autoTestDiscoverOnSavePattern": "placeholder"
8384
},
8485
"terminal": {
8586
"activateEnvironment": true,

src/client/common/configSettings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ export class PythonSettings implements IPythonSettings {
320320
unittestEnabled: false,
321321
pytestPath: 'pytest',
322322
autoTestDiscoverOnSaveEnabled: true,
323+
autoTestDiscoverOnSavePattern: "**.py"
323324
} as ITestingSettings;
324325
}
325326
}
@@ -336,6 +337,7 @@ export class PythonSettings implements IPythonSettings {
336337
unittestArgs: [],
337338
unittestEnabled: false,
338339
autoTestDiscoverOnSaveEnabled: true,
340+
autoTestDiscoverOnSavePattern: "**.py",
339341
};
340342
this.testing.pytestPath = getAbsolutePath(systemVariables.resolveAny(this.testing.pytestPath), workspaceRoot);
341343
if (this.testing.cwd) {

src/client/testing/configuration/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface ITestingSettings {
1111
unittestArgs: string[];
1212
cwd?: string;
1313
readonly autoTestDiscoverOnSaveEnabled: boolean;
14+
readonly autoTestDiscoverOnSavePattern: string;
1415
}
1516

1617
export type TestSettingsPropertyNames = {

src/client/testing/testController/controller.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import { inject, injectable, named } from 'inversify';
55
import { uniq } from 'lodash';
6+
import { minimatch } from 'minimatch';
67
import {
78
CancellationToken,
89
TestController,
@@ -215,7 +216,7 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
215216
if (settings.testing.autoTestDiscoverOnSaveEnabled) {
216217
traceVerbose(`Testing: Setting up watcher for ${workspace.uri.fsPath}`);
217218
this.watchForSettingsChanges(workspace);
218-
this.watchForTestContentChangeOnSave();
219+
this.watchForTestContentChangeOnSave(settings.testing.autoTestDiscoverOnSavePattern);
219220
}
220221
});
221222
}
@@ -549,10 +550,10 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
549550
);
550551
}
551552

552-
private watchForTestContentChangeOnSave(): void {
553+
private watchForTestContentChangeOnSave(testFileGlob: String): void {
553554
this.disposables.push(
554555
onDidSaveTextDocument(async (doc: TextDocument) => {
555-
if (doc.fileName.endsWith('.py')) {
556+
if (minimatch(doc.uri.fs, testFileGlob)) {
556557
traceVerbose(`Testing: Trigger refresh after saving ${doc.uri.fsPath}`);
557558
this.sendTriggerTelemetry('watching');
558559
this.refreshData.trigger(doc.uri, false);

0 commit comments

Comments
 (0)