Python Environments Project Support for Unittest Execution#25779
Merged
eleanorjboyd merged 4 commits intomicrosoft:test-project-supportfrom Feb 9, 2026
Merged
Python Environments Project Support for Unittest Execution#25779eleanorjboyd merged 4 commits intomicrosoft:test-project-supportfrom
eleanorjboyd merged 4 commits intomicrosoft:test-project-supportfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds project-based support for unittest execution/discovery by using the Python Environments “project” model, ensuring the correct interpreter is used per project and that debug sessions are launched with project context.
Changes:
- Pass
project.pythonProjectinto debug launch options for unittest (enables project-derived Python path/session naming). - Prefer
project.pythonEnvironmentovergetEnvironment(uri)when running discovery/execution via the env extension (pytest + unittest). - Enable project-based execution in the test controller whenever projects exist (not only when pytest is enabled), plus add a targeted unittest execution unit test.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/test/testing/testController/unittest/testExecutionAdapter.unit.test.ts | Adds unit tests for project-aware unittest debug options and env-extension execution using the project environment. |
| src/client/testing/testController/unittest/testExecutionAdapter.ts | Passes project into debug launcher and uses project Python environment when useEnvExtension() is enabled. |
| src/client/testing/testController/unittest/testDiscoveryAdapter.ts | Uses project Python environment for env-extension-based unittest discovery. |
| src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts | Uses project Python environment for env-extension-based pytest discovery. |
| src/client/testing/testController/controller.ts | Switches to project-based execution whenever projects exist in the workspace. |
| src/client/testing/testController/common/testDiscoveryHandler.ts | Adds a unittest project-mode warning for likely nested-project import errors during discovery. |
| src/client/testing/common/debugLauncher.ts | Allows default debug cwd to come from the launch options (supports project-root defaulting). |
Comments suppressed due to low confidence (3)
src/client/testing/testController/controller.ts:805
- Project-based execution path bypasses the per-provider enablement checks. With this change, if
hasProjects()is true, tests will be executed even whensettings.testing.pytestEnabled/unittestEnabledare false (e.g. user disables a framework after discovery, but items still exist). Consider gating project execution on the relevant enabled setting(s) and/or filteringprojectsbyproject.testProvideragainst the current settings before callingexecuteTestsForProjects; otherwise fall back tounconfiguredWorkspacesbehavior.
// Check if we're in project-based mode and should use project-specific execution
if (this.projectRegistry.hasProjects(workspace.uri)) {
const projects = this.projectRegistry.getProjectsArray(workspace.uri);
await executeTestsForProjects(projects, testItems, runInstance, request, token, {
projectRegistry: this.projectRegistry,
pythonExecFactory: this.pythonExecFactory,
debugLauncher: this.debugLauncher,
});
return;
}
src/client/testing/testController/unittest/testDiscoveryAdapter.ts:104
- The new project-aware environment selection (
project?.pythonEnvironment ?? getEnvironment(uri)) in the env-extension execution path is not covered by unit tests for unittest discovery. Add a test that passes aProjectAdapterwith a knownpythonEnvironmentand assertsrunInBackgroundis invoked with that environment (and thatgetEnvironment(uri)is not used).
// Execute using environment extension if available
if (useEnvExtension()) {
traceInfo(`Using environment extension for unittest discovery in workspace ${uri.fsPath}`);
const pythonEnv = project?.pythonEnvironment ?? (await getEnvironment(uri));
if (!pythonEnv) {
traceError(
`Python environment not found for workspace ${uri.fsPath}. Cannot proceed with test discovery.`,
);
deferredTillExecClose.resolve();
return;
}
src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts:119
- The new project-aware environment selection (
project?.pythonEnvironment ?? getEnvironment(uri)) in the env-extension execution path is not covered by unit tests for pytest discovery. Add a test that passes aProjectAdapterwith a knownpythonEnvironmentand assertsrunInBackgroundis invoked with that environment (and thatgetEnvironment(uri)is not used).
// Execute using environment extension if available
if (useEnvExtension()) {
traceInfo(`Using environment extension for pytest discovery in workspace ${uri.fsPath}`);
const pythonEnv = project?.pythonEnvironment ?? (await getEnvironment(uri));
if (!pythonEnv) {
traceError(
`Python environment not found for workspace ${uri.fsPath}. Cannot proceed with test discovery.`,
);
deferredTillExecClose.resolve();
return;
}
src/client/testing/testController/common/testDiscoveryHandler.ts
Outdated
Show resolved
Hide resolved
src/test/testing/testController/unittest/testExecutionAdapter.unit.test.ts
Outdated
Show resolved
Hide resolved
f048ef4
into
microsoft:test-project-support
81 of 83 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.