Skip to content

Conversation

@eleanorjboyd
Copy link
Member

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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;
                }

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

1 participant