-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update tests only on save with more files excluded #21741
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import { | |
CancellationTokenSource, | ||
Uri, | ||
EventEmitter, | ||
TextDocument, | ||
} from 'vscode'; | ||
import { IExtensionSingleActivationService } from '../../activation/types'; | ||
import { ICommandManager, IWorkspaceService } from '../../common/application/types'; | ||
|
@@ -48,6 +49,7 @@ import { WorkspaceTestAdapter } from './workspaceTestAdapter'; | |
import { ITestDebugLauncher } from '../common/types'; | ||
import { IServiceContainer } from '../../ioc/types'; | ||
import { PythonResultResolver } from './common/resultResolver'; | ||
import { onDidSaveTextDocument } from '../../common/vscodeApis/workspaceApis'; | ||
|
||
// Types gymnastics to make sure that sendTriggerTelemetry only accepts the correct types. | ||
type EventPropertyType = IEventNamePropertyMapping[EventName.UNITTEST_DISCOVERY_TRIGGER]; | ||
|
@@ -209,7 +211,7 @@ export class PythonTestController implements ITestController, IExtensionSingleAc | |
if (settings.testing.autoTestDiscoverOnSaveEnabled) { | ||
traceVerbose(`Testing: Setting up watcher for ${workspace.uri.fsPath}`); | ||
this.watchForSettingsChanges(workspace); | ||
this.watchForTestContentChanges(workspace); | ||
this.watchForTestContentChangeOnSave(); | ||
} | ||
}); | ||
} | ||
|
@@ -493,12 +495,23 @@ export class PythonTestController implements ITestController, IExtensionSingleAc | |
this.disposables.push(watcher); | ||
|
||
this.disposables.push( | ||
watcher.onDidChange((uri) => { | ||
traceVerbose(`Testing: Trigger refresh after change in ${uri.fsPath}`); | ||
this.sendTriggerTelemetry('watching'); | ||
this.refreshData.trigger(uri, false); | ||
onDidSaveTextDocument(async (doc: TextDocument) => { | ||
const file = doc.fileName; | ||
// refresh on any settings file save | ||
if ( | ||
file.includes('settings.json') || | ||
file.includes('pytest.ini') || | ||
file.includes('setup.cfg') || | ||
file.includes('pyproject.toml') | ||
) { | ||
traceVerbose(`Testing: Trigger refresh after saving ${doc.uri.fsPath}`); | ||
this.sendTriggerTelemetry('watching'); | ||
this.refreshData.trigger(doc.uri, false); | ||
} | ||
}), | ||
); | ||
/* Keep both watchers for create and delete since config files can change test behavior without content | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @karthiknadig please check this and confirm it is correct / makes sense. Thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sense |
||
due to their impact on pythonPath. */ | ||
this.disposables.push( | ||
watcher.onDidCreate((uri) => { | ||
traceVerbose(`Testing: Trigger refresh after creating ${uri.fsPath}`); | ||
|
@@ -515,31 +528,14 @@ export class PythonTestController implements ITestController, IExtensionSingleAc | |
); | ||
} | ||
|
||
private watchForTestContentChanges(workspace: WorkspaceFolder): void { | ||
const pattern = new RelativePattern(workspace, '**/*.py'); | ||
const watcher = this.workspaceService.createFileSystemWatcher(pattern); | ||
this.disposables.push(watcher); | ||
|
||
this.disposables.push( | ||
watcher.onDidChange((uri) => { | ||
traceVerbose(`Testing: Trigger refresh after change in ${uri.fsPath}`); | ||
this.sendTriggerTelemetry('watching'); | ||
// We want to invalidate tests for code change | ||
this.refreshData.trigger(uri, true); | ||
}), | ||
); | ||
this.disposables.push( | ||
watcher.onDidCreate((uri) => { | ||
traceVerbose(`Testing: Trigger refresh after creating ${uri.fsPath}`); | ||
this.sendTriggerTelemetry('watching'); | ||
this.refreshData.trigger(uri, false); | ||
}), | ||
); | ||
private watchForTestContentChangeOnSave(): void { | ||
this.disposables.push( | ||
watcher.onDidDelete((uri) => { | ||
traceVerbose(`Testing: Trigger refresh after deleting in ${uri.fsPath}`); | ||
this.sendTriggerTelemetry('watching'); | ||
this.refreshData.trigger(uri, false); | ||
onDidSaveTextDocument(async (doc: TextDocument) => { | ||
if (doc.fileName.endsWith('.py')) { | ||
traceVerbose(`Testing: Trigger refresh after saving ${doc.uri.fsPath}`); | ||
this.sendTriggerTelemetry('watching'); | ||
this.refreshData.trigger(doc.uri, false); | ||
} | ||
Comment on lines
+531
to
+538
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is nice, should makes things much better. |
||
}), | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
settings.json
only takes effect if it is at the root of the workspace, under.vscode
. So we can probably improve the pattern for it.What about other config files, do we need to watch for pyproject.toml, setup.cfg in any levels of subdirectories?