From c61bbd7ce103fd5e90d64fc66ba053958768d666 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] 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..e48983c5f934 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: "**" } as ITestingSettings; } } @@ -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) { 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..be6b43c6d86f 100644 --- a/src/client/testing/testController/controller.ts +++ b/src/client/testing/testController/controller.ts @@ -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 { @@ -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.default(doc.uri.fs, testFileGlob)) { traceVerbose(`Testing: Trigger refresh after saving ${doc.uri.fsPath}`); this.sendTriggerTelemetry('watching'); this.refreshData.trigger(doc.uri, false);