From b5c1b488c8cf52e74fa9b045dcf29f21d76a1a97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9amus=20=C3=93=20Ceanainn?= Date: Fri, 17 Jan 2025 17:28:36 +0000 Subject: [PATCH 1/5] Introduce autoTestDiscoverOnSavePattern test configuration option --- package.json | 6 ++++++ package.nls.json | 1 + resources/report_issue_user_settings.json | 3 ++- src/client/common/configSettings.ts | 2 ++ src/client/testing/configuration/types.ts | 1 + src/client/testing/testController/controller.ts | 7 ++++--- 6 files changed, 16 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 7f7df96289d7..f521268f7f37 100644 --- a/package.json +++ b/package.json @@ -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%", diff --git a/package.nls.json b/package.nls.json index d744ef430fe4..e1d3dea66f25 100644 --- a/package.nls.json +++ b/package.nls.json @@ -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.", diff --git a/resources/report_issue_user_settings.json b/resources/report_issue_user_settings.json index ef85267c0e65..7e034651c46d 100644 --- a/resources/report_issue_user_settings.json +++ b/resources/report_issue_user_settings.json @@ -79,7 +79,8 @@ "pytestPath": "placeholder", "unittestArgs": "placeholder", "unittestEnabled": true, - "autoTestDiscoverOnSaveEnabled": true + "autoTestDiscoverOnSaveEnabled": true, + "autoTestDiscoverOnSavePattern": "placeholder" }, "terminal": { "activateEnvironment": true, diff --git a/src/client/common/configSettings.ts b/src/client/common/configSettings.ts index 58c41587c4f8..f272c7cc31cf 100644 --- a/src/client/common/configSettings.ts +++ b/src/client/common/configSettings.ts @@ -320,6 +320,7 @@ export class PythonSettings implements IPythonSettings { unittestEnabled: false, pytestPath: 'pytest', autoTestDiscoverOnSaveEnabled: true, + autoTestDiscoverOnSavePattern: "**.py" } as ITestingSettings; } } @@ -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) { diff --git a/src/client/testing/configuration/types.ts b/src/client/testing/configuration/types.ts index 5da99398283b..3b759bcb39e8 100644 --- a/src/client/testing/configuration/types.ts +++ b/src/client/testing/configuration/types.ts @@ -11,6 +11,7 @@ export interface ITestingSettings { unittestArgs: string[]; cwd?: string; readonly autoTestDiscoverOnSaveEnabled: boolean; + readonly autoTestDiscoverOnSavePattern: string; } export type TestSettingsPropertyNames = { diff --git a/src/client/testing/testController/controller.ts b/src/client/testing/testController/controller.ts index 6142140b3e2e..aae400326b0e 100644 --- a/src/client/testing/testController/controller.ts +++ b/src/client/testing/testController/controller.ts @@ -3,6 +3,7 @@ import { inject, injectable, named } from 'inversify'; import { uniq } from 'lodash'; +import { minimatch } from 'minimatch'; import { CancellationToken, TestController, @@ -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); } }); } @@ -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(doc.uri.fs, testFileGlob)) { traceVerbose(`Testing: Trigger refresh after saving ${doc.uri.fsPath}`); this.sendTriggerTelemetry('watching'); this.refreshData.trigger(doc.uri, false); From 8b06a938cb57b97ba850a47849715a0fdc006a83 Mon Sep 17 00:00:00 2001 From: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> Date: Thu, 13 Feb 2025 13:40:04 -0800 Subject: [PATCH 2/5] few small fixes --- src/client/testing/testController/controller.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/client/testing/testController/controller.ts b/src/client/testing/testController/controller.ts index aae400326b0e..98a7f909a8e2 100644 --- a/src/client/testing/testController/controller.ts +++ b/src/client/testing/testController/controller.ts @@ -3,7 +3,7 @@ import { inject, injectable, named } from 'inversify'; import { uniq } from 'lodash'; -import { minimatch } from 'minimatch'; +import * as minimatch from 'minimatch'; import { CancellationToken, TestController, @@ -216,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(settings.testing.autoTestDiscoverOnSavePattern); + this.watchForTestContentChangeOnSave(); } }); } @@ -550,10 +550,11 @@ export class PythonTestController implements ITestController, IExtensionSingleAc ); } - private watchForTestContentChangeOnSave(testFileGlob: String): void { + private watchForTestContentChangeOnSave(): void { this.disposables.push( onDidSaveTextDocument(async (doc: TextDocument) => { - if (minimatch(doc.uri.fs, testFileGlob)) { + 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); From bdd9205153043530cb6699874e633bc73795e0ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9amus=20=C3=93=20Ceanainn?= Date: Fri, 14 Feb 2025 15:40:04 +0000 Subject: [PATCH 3/5] Fix linting --- src/client/common/configSettings.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/common/configSettings.ts b/src/client/common/configSettings.ts index f272c7cc31cf..2f4f34d05b85 100644 --- a/src/client/common/configSettings.ts +++ b/src/client/common/configSettings.ts @@ -320,7 +320,7 @@ export class PythonSettings implements IPythonSettings { unittestEnabled: false, pytestPath: 'pytest', autoTestDiscoverOnSaveEnabled: true, - autoTestDiscoverOnSavePattern: "**.py" + autoTestDiscoverOnSavePattern: '**.py', } as ITestingSettings; } } @@ -337,7 +337,7 @@ export class PythonSettings implements IPythonSettings { unittestArgs: [], unittestEnabled: false, autoTestDiscoverOnSaveEnabled: true, - autoTestDiscoverOnSavePattern: "**.py", + autoTestDiscoverOnSavePattern: '**.py', }; this.testing.pytestPath = getAbsolutePath(systemVariables.resolveAny(this.testing.pytestPath), workspaceRoot); if (this.testing.cwd) { From 363e579f1d70cf3d4b15ba778aaa7a75c4ef2b5a Mon Sep 17 00:00:00 2001 From: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> Date: Fri, 14 Feb 2025 09:47:22 -0800 Subject: [PATCH 4/5] update default glob to **/*.py --- package.json | 2 +- src/client/common/configSettings.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 193252cc46ed..f773c32c08da 100644 --- a/package.json +++ b/package.json @@ -658,7 +658,7 @@ "type": "boolean" }, "python.testing.autoTestDiscoverOnSavePattern": { - "default": "**.py", + "default": "**/*.py", "description": "%python.testing.autoTestDiscoverOnSavePattern.description%", "scope": "resource", "type": "string" diff --git a/src/client/common/configSettings.ts b/src/client/common/configSettings.ts index 2f4f34d05b85..c4594a89f999 100644 --- a/src/client/common/configSettings.ts +++ b/src/client/common/configSettings.ts @@ -320,7 +320,7 @@ export class PythonSettings implements IPythonSettings { unittestEnabled: false, pytestPath: 'pytest', autoTestDiscoverOnSaveEnabled: true, - autoTestDiscoverOnSavePattern: '**.py', + autoTestDiscoverOnSavePattern: '**/*.py', } as ITestingSettings; } } From 233569307ef9f232aa06707afae799f36a640a62 Mon Sep 17 00:00:00 2001 From: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> Date: Fri, 14 Feb 2025 09:48:38 -0800 Subject: [PATCH 5/5] update another place --- src/client/common/configSettings.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/common/configSettings.ts b/src/client/common/configSettings.ts index c4594a89f999..7ae3467b2cfd 100644 --- a/src/client/common/configSettings.ts +++ b/src/client/common/configSettings.ts @@ -337,7 +337,7 @@ export class PythonSettings implements IPythonSettings { unittestArgs: [], unittestEnabled: false, autoTestDiscoverOnSaveEnabled: true, - autoTestDiscoverOnSavePattern: '**.py', + autoTestDiscoverOnSavePattern: '**/*.py', }; this.testing.pytestPath = getAbsolutePath(systemVariables.resolveAny(this.testing.pytestPath), workspaceRoot); if (this.testing.cwd) {