You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/instructions/testing_feature_area.instructions.md
+34-7Lines changed: 34 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -159,8 +159,6 @@ The adapters in the extension don't implement test discovery/run logic themselve
159
159
160
160
Project-based testing enables multi-project workspace support where each Python project gets its own test tree root with its own Python environment.
161
161
162
-
> **⚠️ Note: unittest support for project-based testing is NOT yet implemented.** Project-based testing currently only works with pytest. unittest support will be added in a future PR.
163
-
164
162
### Architecture
165
163
166
164
-**TestProjectRegistry** (`testProjectRegistry.ts`): Central registry that:
@@ -182,23 +180,52 @@ Project-based testing enables multi-project workspace support where each Python
182
180
2.**Project discovery**: `TestProjectRegistry.discoverAndRegisterProjects()` queries the API for all Python projects in each workspace.
183
181
3.**Nested handling**: `configureNestedProjectIgnores()` identifies child projects and adds their paths to parent projects' ignore lists.
184
182
4.**Test discovery**: For each project, the controller calls `project.discoveryAdapter.discoverTests()` with the project's URI. The adapter sets `PROJECT_ROOT_PATH` environment variable for the Python runner.
185
-
5.**Python side**: `get_test_root_path()` in `vscode_pytest/__init__.py` returns `PROJECT_ROOT_PATH` (if set) or falls back to `cwd`.
186
-
6.**Test tree**: Each project gets its own root node in the Test Explorer, with test IDs scoped by project ID using the `||` separator.
183
+
5.**Python side**:
184
+
- For pytest: `get_test_root_path()` in `vscode_pytest/__init__.py` returns `PROJECT_ROOT_PATH` (if set) or falls back to `cwd`.
185
+
- For unittest: `discovery.py` uses `PROJECT_ROOT_PATH` as `top_level_dir` and `project_root_path` to root the test tree at the project directory.
186
+
6.**Test tree**: Each project gets its own root node in the Test Explorer, with test IDs scoped by project ID using the `@@vsc@@` separator (defined in `projectUtils.ts`).
187
+
188
+
### Nested project handling: pytest vs unittest
189
+
190
+
**pytest** supports the `--ignore` flag to exclude paths during test collection. When nested projects are detected, parent projects automatically receive `--ignore` flags for child project paths. This ensures each test appears under exactly one project in the test tree.
191
+
192
+
**unittest** does not support path exclusion during `discover()`. Therefore, tests in nested project directories may appear under multiple project roots (both the parent and the child project). This is **expected behavior** for unittest:
193
+
194
+
- Each project discovers and displays all tests it finds within its directory structure
195
+
- There is no deduplication or collision detection
196
+
- Users may see the same test file under multiple project roots if their project structure has nesting
197
+
198
+
This approach was chosen because:
199
+
200
+
1. unittest's `TestLoader.discover()` has no built-in path exclusion mechanism
201
+
2. Implementing custom exclusion would add significant complexity with minimal benefit
202
+
3. The existing approach is transparent and predictable - each project shows what it finds
203
+
204
+
### Empty projects and root nodes
205
+
206
+
If a project discovers zero tests, its root node will still appear in the Test Explorer as an empty folder. This ensures consistent behavior and makes it clear which projects were discovered, even if they have no tests yet.
187
207
188
208
### Logging prefix
189
209
190
210
All project-based testing logs use the `[test-by-project]` prefix for easy filtering in the output channel.
191
211
192
212
### Key files
193
213
194
-
- Python side: `python_files/vscode_pytest/__init__.py` — `get_test_root_path()` function and `PROJECT_ROOT_PATH` environment variable.
195
-
- TypeScript: `testProjectRegistry.ts`, `projectAdapter.ts`, `projectUtils.ts`, and the discovery adapters.
214
+
- Python side:
215
+
-`python_files/vscode_pytest/__init__.py` — `get_test_root_path()` function and `PROJECT_ROOT_PATH` environment variable for pytest.
216
+
-`python_files/unittestadapter/discovery.py` — `discover_tests()` with `project_root_path` parameter and `PROJECT_ROOT_PATH` handling for unittest discovery.
217
+
-`python_files/unittestadapter/execution.py` — `run_tests()` with `project_root_path` parameter and `PROJECT_ROOT_PATH` handling for unittest execution.
218
+
- TypeScript: `testProjectRegistry.ts`, `projectAdapter.ts`, `projectUtils.ts`, and the discovery/execution adapters.
-`python_files/tests/pytestadapter/test_discovery.py` — pytest PROJECT_ROOT_PATH tests (see `test_project_root_path_env_var()` and `test_symlink_with_project_root_path()`)
0 commit comments