Add support for Projects in Testing #25780
Merged
eleanorjboyd merged 14 commits intomainfrom Feb 10, 2026
Merged
Conversation
## Summary This PR implements **project-based test discovery** for pytest, enabling multi-project workspace support. When the Python Environments API is available, the extension now discovers Python projects within workspaces and creates separate test tree roots for each project with its own Python environment. ## What's New ### Project-Based Testing Architecture - **TestProjectRegistry**: Manages the lifecycle of Python test projects, including: - Discovering projects via Python Environments API - Creating ProjectAdapter instances per workspace - Computing nested project relationships for ignore lists - Fallback to "legacy" single-adapter mode when API unavailable - **ProjectAdapter**: Interface representing a single Python project with test infrastructure: - Project identity (ID, name, URI) - Python environment from the environments API - Test framework adapters (discovery/execution) - Nested project ignore paths ### Key Features - ✅ **Multi-project workspaces**: Each Python project gets its own test tree root - ✅ **Nested project handling**: Parent projects automatically ignore nested child projects via `--ignore` flags - ✅ **Graceful fallback**: Falls back to legacy single-adapter mode if Python Environments API is unavailable - ✅ **Project root path**: Python-side `get_test_root_path()` function returns appropriate root for test tree ### Code Improvements - Standardized logging prefixes to `[test-by-project]` across all files - Centralized adapter creation via `createTestAdapters()` helper method - Extracted reusable methods for discovery, execution, and file watching ## Scope & Limitations > **⚠️ Important: unittest is NOT supported in this PR** > > This PR focuses exclusively on **pytest**. unittest support for project-based testing will be implemented in a future PR. ## Testing - Added unit tests for `TestProjectRegistry` class - Added unit tests for Python-side `get_test_root_path()` function - Manual testing with multi-project workspaces ## Related Issues first step in: microsoft/vscode-python-environments#987 --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This adds a place within the github workspace that developers can store any AI related artifacts they create that could be useful but they don't want to commit. Things like issue summarization, plans for features, code analysis etc
There was a problem hiding this comment.
Pull request overview
This PR adds project-based (multi-project) testing support to the VS Code Python extension’s Test Explorer integration, leveraging the Python Environments API so each project can be discovered/run/debugged with its own environment (fixes microsoft/vscode-python-environments#987).
Changes:
- Introduces a project registry + project adapter model to discover/register multiple Python projects per workspace and run discovery/execution per project.
- Scopes VS Code test IDs by project (via a project ID separator) and threads project context through discovery/execution adapters (including
PROJECT_ROOT_PATHsupport in Python runner scripts). - Adds extensive unit tests (TS + Python) covering project-based discovery/execution, nested project behavior, and debug session handling.
Reviewed changes
Copilot reviewed 36 out of 36 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/client/testing/testController/controller.ts | Adds project-based activation/discovery/execution flow and project-change handling. |
| src/client/testing/testController/common/testProjectRegistry.ts | New registry for discovering projects, creating project-specific adapters/resolvers, and nested ignore computation. |
| src/client/testing/testController/common/projectAdapter.ts | Defines per-project adapter shape (env + adapters + resolver + lifecycle). |
| src/client/testing/testController/common/projectUtils.ts | Adds project ID scoping utilities + shared adapter creation helper. |
| src/client/testing/testController/common/projectTestExecution.ts | Executes selected tests grouped by owning project with project-specific environment/debug/coverage behavior. |
| src/client/testing/testController/common/utils.ts | Adds project-scoped IDs in populateTestTree() and project-aware error labels. |
| src/client/testing/testController/common/testDiscoveryHandler.ts | Routes discovery into project-scoped IDs and project-scoped error nodes. |
| src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts | Threads ProjectAdapter through discovery; adds nested --ignore support; sets PROJECT_ROOT_PATH. |
| src/client/testing/testController/pytest/pytestExecutionAdapter.ts | Threads ProjectAdapter through execution; uses project env when available; sets PROJECT_ROOT_PATH. |
| src/client/testing/testController/unittest/testDiscoveryAdapter.ts | Threads ProjectAdapter through discovery; uses project env when available; sets PROJECT_ROOT_PATH. |
| src/client/testing/testController/unittest/testExecutionAdapter.ts | Threads ProjectAdapter through execution/debug; uses project env when available; sets PROJECT_ROOT_PATH. |
| src/client/testing/testController/workspaceTestAdapter.ts | Allows passing a ProjectAdapter to execution for project-scoped runs. |
| src/client/testing/common/debugLauncher.ts | Adds multi-session tracking via markers; supports project-based debug naming + Python path resolution. |
| python_files/vscode_pytest/init.py | Uses PROJECT_ROOT_PATH to root discovery/execution payload cwd/test-tree root for project mode. |
| python_files/unittestadapter/discovery.py | Supports PROJECT_ROOT_PATH to override cwd/top-level behavior for project-rooted discovery. |
| python_files/unittestadapter/execution.py | Supports PROJECT_ROOT_PATH to override cwd in execution payloads. |
| src/test/vscode-mock.ts | Adds vscode.tests.createTestController() mock for unit tests. |
| src/test/testing/testController/** | Adds unit tests for project registry, project execution grouping, controller behavior, adapters, and utilities. |
| python_files/tests/** | Adds Python-side tests for PROJECT_ROOT_PATH behavior for both unittest + pytest. |
| .github/instructions/testing_feature_area.instructions.md | Documents the new project-based testing architecture and key files/tests. |
src/client/testing/testController/common/testProjectRegistry.ts
Outdated
Show resolved
Hide resolved
karthiknadig
approved these changes
Feb 10, 2026
eleanorjboyd
added a commit
to eleanorjboyd/vscode-python
that referenced
this pull request
Feb 10, 2026
fixes microsoft/vscode-python-environments#987 --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
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.
fixes microsoft/vscode-python-environments#987