Skip to content

Commit 2abfbbe

Browse files
committed
remove comments
1 parent 267007b commit 2abfbbe

File tree

4 files changed

+16
-118
lines changed

4 files changed

+16
-118
lines changed

python_files/unittestadapter/pvsc_utils.py

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -166,44 +166,6 @@ def get_child_node(name: str, path: str, type_: TestNodeTypeEnum, root: TestNode
166166
return result # type:ignore
167167

168168

169-
# TODO: Unittest nested project exclusion - commented out for now, focusing on pytest first
170-
# def should_exclude_file(test_path: str) -> bool:
171-
# """Check if a test file should be excluded due to nested project ownership.
172-
#
173-
# Reads NESTED_PROJECTS_TO_IGNORE environment variable (JSON array of paths)
174-
# and checks if test_path is under any of those nested project directories.
175-
#
176-
# Args:
177-
# test_path: Absolute path to the test file
178-
#
179-
# Returns:
180-
# True if the file should be excluded, False otherwise
181-
# """
182-
# nested_projects_json = os.getenv("NESTED_PROJECTS_TO_IGNORE")
183-
# if not nested_projects_json:
184-
# return False
185-
#
186-
# try:
187-
# nested_paths = json.loads(nested_projects_json)
188-
# test_path_obj = pathlib.Path(test_path).resolve()
189-
#
190-
# # Check if test file is under any nested project path
191-
# for nested_path in nested_paths:
192-
# nested_path_obj = pathlib.Path(nested_path).resolve()
193-
# try:
194-
# test_path_obj.relative_to(nested_path_obj)
195-
# # If relative_to succeeds, test_path is under nested_path
196-
# return True
197-
# except ValueError:
198-
# # test_path is not under nested_path
199-
# continue
200-
#
201-
# return False
202-
# except Exception:
203-
# # On any error, don't exclude (safer to show tests than hide them)
204-
# return False
205-
206-
207169
def build_test_tree(
208170
suite: unittest.TestSuite, top_level_directory: str
209171
) -> Tuple[Union[TestNode, None], List[str]]:
@@ -290,12 +252,6 @@ def build_test_tree(
290252
path_components = [top_level_directory, *folders, py_filename]
291253
file_path = os.fsdecode(pathlib.PurePath("/".join(path_components)))
292254

293-
# PHASE 4: Check if file should be excluded (nested project ownership)
294-
# TODO: Commented out for now - focusing on pytest implementation first
295-
# if should_exclude_file(file_path):
296-
# # Skip this test - it belongs to a nested project
297-
# continue
298-
299255
current_node = get_child_node(
300256
py_filename, file_path, TestNodeTypeEnum.file, current_node
301257
)

src/client/testing/testController/controller.ts

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,17 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
7070

7171
/**
7272
* Feature flag for project-based testing.
73-
* Set to true to enable multi-project testing support (Phases 2-4 must be complete).
74-
* Default: false (use legacy single-workspace mode)
73+
* When true, discovers and manages tests per-project using Python Environments API.
74+
* When false, uses legacy single-workspace mode.
7575
*/
7676
private readonly useProjectBasedTesting = true;
7777

7878
// Legacy: Single workspace test adapter per workspace (backward compatibility)
7979
private readonly testAdapters: Map<Uri, WorkspaceTestAdapter> = new Map();
8080

81-
// === NEW: PROJECT-BASED STATE ===
82-
// Map of workspace URI -> Map of project URI string -> ProjectAdapter
83-
// Note: Project URI strings match Python Environments extension's Map<string, PythonProject> keys
81+
// Project-based testing: Maps workspace URI -> project ID -> ProjectAdapter
8482
private readonly workspaceProjects: Map<Uri, Map<string, ProjectAdapter>> = new Map();
8583

86-
// TODO: Phase 3-4 - Add these maps when implementing execution:
87-
// - vsIdToProject: Map<string, ProjectAdapter> - Fast lookup for test execution
88-
// - fileUriToProject: Map<string, ProjectAdapter> - File watching and change detection
89-
// - projectToVsIds: Map<string, Set<string>> - Project cleanup and refresh
90-
9184
private readonly triggerTypes: TriggerType[] = [];
9285

9386
private readonly testController: TestController;
@@ -333,7 +326,7 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
333326
const pythonProjects = envExtApi.getPythonProjects();
334327
traceInfo(`[test-by-project] Found ${pythonProjects.length} total Python projects from API`);
335328

336-
// Filter projects to only those in this workspace TODO; check this
329+
// Filter projects to only those in this workspace
337330
const workspaceProjects = pythonProjects.filter((project) =>
338331
isParentPath(project.uri.fsPath, workspaceUri.fsPath),
339332
);
@@ -567,14 +560,11 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
567560
}
568561

569562
/**
570-
* Phase 3: Identifies which projects are nested within other projects in the same workspace.
563+
* Identifies which projects are nested within other projects in the same workspace.
571564
* Returns a map of parent project ID -> array of nested child project paths to ignore.
572565
*
573566
* Example: If ProjectB (alice/bob/) is nested in ProjectA (alice/),
574567
* returns: { "projectA-id": ["alice/bob"] }
575-
*
576-
* Uses simple path prefix matching - a project is nested if its path starts with
577-
* another project's path followed by a path separator.
578568
*/
579569
private computeNestedProjectIgnores(workspaceUri: Uri): Map<string, string[]> {
580570
const projectIgnores = new Map<string, string[]>();
@@ -623,9 +613,8 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
623613
}
624614

625615
/**
626-
* Phase 2: Discovers tests for all projects within a workspace (project-based testing).
627-
* Runs discovery in parallel for all projects and tracks file overlaps for Phase 3.
628-
* Each project populates its TestItems independently using the existing discovery flow.
616+
* Discovers tests for all projects within a workspace.
617+
* Runs discovery in parallel and configures nested project exclusions.
629618
*/
630619
private async refreshWorkspaceProjects(workspaceUri: Uri): Promise<void> {
631620
const projectsMap = this.workspaceProjects.get(workspaceUri);
@@ -638,7 +627,7 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
638627
traceInfo(`[test-by-project] Starting discovery for ${projects.length} project(s) in workspace`);
639628

640629
try {
641-
// PHASE 3: Compute nested project relationships BEFORE discovery
630+
// Compute nested project relationships BEFORE discovery
642631
const projectIgnores = this.computeNestedProjectIgnores(workspaceUri);
643632

644633
// Populate each project's ignore list by iterating through projects array directly
@@ -672,34 +661,18 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
672661

673662
/**
674663
* Runs test discovery for a single project.
675-
* Uses the existing discovery flow which populates TestItems automatically.
676664
*/
677665
private async discoverProject(project: ProjectAdapter, projectsCompleted: Set<string>): Promise<void> {
678666
try {
679667
traceInfo(`[test-by-project] Discovering tests for project: ${project.projectName}`);
680668
project.isDiscovering = true;
681669

682-
// Run discovery using project's adapter with project's interpreter
683-
// This will call the existing discovery flow which populates TestItems via result resolver
684-
// Note: The adapter expects the legacy PythonEnvironment type, but for now we can pass
685-
// the environment from the API. The adapters internally use execInfo which both types have.
686-
//
687-
// Pass the ProjectAdapter so discovery adapters can extract project.projectUri.fsPath
688-
// and set PROJECT_ROOT_PATH environment variable. This tells Python subprocess where to
689-
// trim the test tree, keeping test paths relative to project root instead of workspace root,
690-
// while preserving CWD for user's test configurations.
691-
//
692-
// TODO: Symlink consideration - If project.projectUri.fsPath contains symlinks,
693-
// Python's path resolution may differ from Node.js. Discovery adapters should consider
694-
// using fs.promises.realpath() to resolve symlinks before passing PROJECT_ROOT_PATH to Python,
695-
// similar to handleSymlinkAndRootDir() in pytest. This ensures PROJECT_ROOT_PATH matches
696-
// the resolved path Python will use.
697670
await project.discoveryAdapter.discoverTests(
698671
project.projectUri,
699672
this.pythonExecFactory,
700673
this.refreshCancellation.token,
701-
project.pythonEnvironment as any, // Type cast needed - API type vs legacy type
702-
project, // Pass project for access to projectUri and other project-specific data
674+
project.pythonEnvironment as any,
675+
project,
703676
);
704677

705678
// Mark project as completed

src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,14 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
7979
const cwd = settings.testing.cwd && settings.testing.cwd.length > 0 ? settings.testing.cwd : uri.fsPath;
8080
pytestArgs = await handleSymlinkAndRootDir(cwd, pytestArgs);
8181

82-
// PHASE 4: Add --ignore flags for nested projects
83-
traceVerbose(
84-
`[test-by-project] Checking for nested projects to ignore. Project: ${project?.projectName}, ` +
85-
`nestedProjectPathsToIgnore length: ${project?.nestedProjectPathsToIgnore?.length ?? 0}`,
86-
);
82+
// Add --ignore flags for nested projects to prevent duplicate discovery
8783
if (project?.nestedProjectPathsToIgnore?.length) {
8884
const ignoreArgs = project.nestedProjectPathsToIgnore.map((nestedPath) => `--ignore=${nestedPath}`);
8985
pytestArgs = [...pytestArgs, ...ignoreArgs];
9086
traceInfo(
91-
`[test-by-project] Project ${project.projectName} ignoring ${ignoreArgs.length} ` +
92-
`nested project(s): ${ignoreArgs.join(' ')}`,
93-
);
94-
} else {
95-
traceVerbose(
96-
`[test-by-project] No nested projects to ignore for project: ${project?.projectName ?? 'unknown'}`,
87+
`[test-by-project] Project ${project.projectName} ignoring nested project(s): ${ignoreArgs.join(
88+
' ',
89+
)}`,
9790
);
9891
}
9992

@@ -105,13 +98,7 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
10598
// Configure subprocess environment
10699
const mutableEnv = await configureDiscoveryEnv(this.envVarsService, uri, discoveryPipeName);
107100

108-
// Set PROJECT_ROOT_PATH for project-based testing
109-
// This tells Python where to trim the test tree, keeping test paths relative to project root
110-
// instead of workspace root, while preserving CWD for user's test configurations.
111-
// Using fsPath for cross-platform compatibility (handles Windows vs Unix paths).
112-
// TODO: Symlink consideration - PROJECT_ROOT_PATH may contain symlinks. If handleSymlinkAndRootDir()
113-
// resolves the CWD to a different path, PROJECT_ROOT_PATH might not match. Consider resolving
114-
// PROJECT_ROOT_PATH symlinks before passing, or adjust Python-side logic to handle both paths.
101+
// Set PROJECT_ROOT_PATH for project-based testing (tells Python where to root the test tree)
115102
if (project) {
116103
mutableEnv.PROJECT_ROOT_PATH = project.projectUri.fsPath;
117104
}

src/client/testing/testController/unittest/testDiscoveryAdapter.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,29 +80,11 @@ export class UnittestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
8080
// Configure subprocess environment
8181
const mutableEnv = await configureDiscoveryEnv(this.envVarsService, uri, discoveryPipeName);
8282

83-
// Set PROJECT_ROOT_PATH for project-based testing
84-
// This tells Python where to trim the test tree, keeping test paths relative to project root
85-
// instead of workspace root, while preserving CWD for user's test configurations.
86-
// Using fsPath for cross-platform compatibility (handles Windows vs Unix paths).
87-
// TODO: Symlink consideration - If CWD or PROJECT_ROOT_PATH contain symlinks, path matching
88-
// in Python may fail. Consider resolving symlinks before comparison, or using os.path.realpath()
89-
// on the Python side to normalize paths before building test tree.
83+
// Set PROJECT_ROOT_PATH for project-based testing (tells Python where to root the test tree)
9084
if (project) {
9185
mutableEnv.PROJECT_ROOT_PATH = project.projectUri.fsPath;
9286
}
9387

94-
// PHASE 4: Pass exclusion list via environment variable for unittest
95-
// TODO: unittest doesn't have a built-in --ignore flag like pytest, so we'll need to pass the
96-
// nested project paths via environment and handle filtering in Python-side discovery.py
97-
// Commenting out for now - focusing on pytest implementation first
98-
// if (project?.nestedProjectPathsToIgnore?.length) {
99-
// mutableEnv.NESTED_PROJECTS_TO_IGNORE = JSON.stringify(project.nestedProjectPathsToIgnore);
100-
// traceInfo(
101-
// `[test-by-project] Project ${project.projectName} will exclude ${project.nestedProjectPathsToIgnore.length} ` +
102-
// `nested project(s) in Python-side unittest discovery`
103-
// );
104-
// }
105-
10688
// Setup process handlers (shared by both execution paths)
10789
const handlers = createProcessHandlers('unittest', uri, cwd, this.resultResolver, deferredTillExecClose);
10890

0 commit comments

Comments
 (0)