Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
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: '**.py',
} as ITestingSettings;
}
}
Expand All @@ -336,6 +337,7 @@ export class PythonSettings implements IPythonSettings {
unittestArgs: [],
unittestEnabled: false,
autoTestDiscoverOnSaveEnabled: true,
autoTestDiscoverOnSavePattern: '**.py',
};
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
4 changes: 3 additions & 1 deletion src/client/testing/testController/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { inject, injectable, named } from 'inversify';
import { uniq } from 'lodash';
import * as minimatch from 'minimatch';
import {
CancellationToken,
TestController,
Expand Down Expand Up @@ -552,7 +553,8 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
private watchForTestContentChangeOnSave(): void {
this.disposables.push(
onDidSaveTextDocument(async (doc: TextDocument) => {
if (doc.fileName.endsWith('.py')) {
const settings = this.configSettings.getSettings(doc.uri);
if (minimatch.default(doc.uri.fsPath, settings.testing.autoTestDiscoverOnSavePattern)) {
traceVerbose(`Testing: Trigger refresh after saving ${doc.uri.fsPath}`);
this.sendTriggerTelemetry('watching');
this.refreshData.trigger(doc.uri, false);
Expand Down
Loading