-
Notifications
You must be signed in to change notification settings - Fork 1.3k
test discovery 2.0 #25760
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
base: main
Are you sure you want to change the base?
test discovery 2.0 #25760
Conversation
- Created ProjectAdapter and WorkspaceDiscoveryState interfaces - Added project utility functions (ID generation, scoping, nested project detection) - Updated PythonResultResolver to support optional projectId parameter - Modified populateTestTree to create project-scoped test IDs - Updated TestDiscoveryHandler to handle project-scoped error nodes Co-authored-by: eleanorjboyd <[email protected]>
- Added project-based state maps (workspaceProjects, vsIdToProject, fileUriToProject, projectToVsIds) - Implemented discoverWorkspaceProjects() to query Python Environment API - Created createProjectAdapter() to build ProjectAdapter from PythonProject - Added createDefaultProject() for backward compatibility - Imported necessary types from environment API - Added flag to enable/disable project-based testing Co-authored-by: eleanorjboyd <[email protected]>
- Modified activate() to check useProjectBasedTesting flag - Calls discoverWorkspaceProjects() for each workspace when enabled - Populates workspaceProjects map with discovered projects - Created activateLegacyWorkspace() for backward compatibility - Falls back to legacy mode if project discovery fails - Maintains full backward compatibility with flag disabled Co-authored-by: eleanorjboyd <[email protected]>
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.
Pull request overview
This PR implements project-based test discovery for pytest, enabling multi-project workspace support where each Python project gets its own test tree root with its own Python environment. When the Python Environments API is available, the extension now discovers Python projects within workspaces and creates separate test adapters for each project.
Changes:
- Introduces TestProjectRegistry for managing project lifecycle, discovery, and nested project handling
- Adds ProjectAdapter interface representing individual Python projects with test infrastructure
- Implements Python-side
get_test_root_path()function to support project-scoped test trees - Adds comprehensive unit tests for project registry, utilities, and Python-side functions
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/client/testing/testController/controller.ts | Refactored activation to support project-based and legacy modes, added project discovery orchestration |
| src/client/testing/testController/common/testProjectRegistry.ts | New registry class managing Python project discovery, adapter creation, and nested project ignore lists |
| src/client/testing/testController/common/projectAdapter.ts | New interface defining structure for project-based test infrastructure |
| src/client/testing/testController/common/projectUtils.ts | Utility functions for project ID generation, display names, and adapter creation |
| src/client/testing/testController/common/resultResolver.ts | Added optional projectId parameter for scoping test IDs to projects |
| src/client/testing/testController/common/utils.ts | Modified populateTestTree to support project-scoped test IDs with separator |
| src/client/testing/testController/common/types.ts | Extracted ITestItemMappings interface, added optional project parameter to ITestDiscoveryAdapter |
| src/client/testing/testController/common/testDiscoveryHandler.ts | Updated error node creation to support project-scoped IDs |
| src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts | Added PROJECT_ROOT_PATH env var and --ignore flags for nested projects |
| python_files/vscode_pytest/init.py | Implemented get_test_root_path() function to return project root or cwd for test tree structure |
| src/test/testing/testController/controller.unit.test.ts | Added tests for controller project-based testing functionality |
| src/test/testing/testController/common/testProjectRegistry.unit.test.ts | Comprehensive tests for TestProjectRegistry class |
| src/test/testing/testController/common/projectUtils.unit.test.ts | Tests for project utility functions (getProjectId, parseVsId, createProjectDisplayName) |
| python_files/tests/pytestadapter/test_discovery.py | Added test_project_root_path_env_var() to verify PROJECT_ROOT_PATH behavior |
| python_files/tests/pytestadapter/expected_discovery_test_output.py | Added expected output for PROJECT_ROOT_PATH test scenario |
| .github/instructions/testing_feature_area.instructions.md | Documented project-based testing architecture and workflow |
| .github/instructions/testing-workflow.instructions.md | Added learning about stubbing after refactoring |
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:
ProjectAdapter: Interface representing a single Python project with test infrastructure:
Key Features
--ignoreflagsget_test_root_path()function returns appropriate root for test treeCode Improvements
[test-by-project]across all filescreateTestAdapters()helper methodScope & Limitations
Testing
TestProjectRegistryclassget_test_root_path()functionRelated Issues
first step in: microsoft/vscode-python-environments#987