FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Python Environments Project Support for Unittest Execution by eleanorjboyd · Pull Request #25779 · microsoft/vscode-python · GitHub

Python Environments Project Support for Unittest Execution - #25779

Merged
Eleanor Boyd (eleanorjboyd) merged 4 commits into
microsoft:test-project-supportfrom
eleanorjboyd:unittest-2.0
Feb 9, 2026
Merged

Python Environments Project Support for Unittest Execution#25779
Eleanor Boyd (eleanorjboyd) merged 4 commits into
microsoft:test-project-supportfrom
eleanorjboyd:unittest-2.0

Conversation

Copy link
Copy Markdown
Member

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.pythonProject into debug launch options for unittest (enables project-derived Python path/session naming).
  • Prefer project.pythonEnvironment over getEnvironment(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 when settings.testing.pytestEnabled/unittestEnabled are 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 filtering projects by project.testProvider against the current settings before calling executeTestsForProjects; otherwise fall back to unconfiguredWorkspaces behavior.
        // 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 a ProjectAdapter with a known pythonEnvironment and asserts runInBackground is invoked with that environment (and that getEnvironment(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 a ProjectAdapter with a known pythonEnvironment and asserts runInBackground is invoked with that environment (and that getEnvironment(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;
                }

Eleanor Boyd (eleanorjboyd) added feature-request Request for new features or functionality skip-issue-check labels Feb 9, 2026
Eleanor Boyd (eleanorjboyd) marked this pull request as ready for review February 9, 2026 21:48
Eleanor Boyd (eleanorjboyd) merged commit f048ef4 into microsoft:test-project-support Feb 9, 2026
81 of 83 checks passed
Eleanor Boyd (eleanorjboyd) deleted the unittest-2.0 branch February 9, 2026 21:49
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

Labels

feature-request Request for new features or functionality skip-issue-check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL