fix(testing): respect TestRunRequest.exclude when running tests #25743
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.
The VS Code Test Explorer API specifies that TestRunRequest.exclude contains tests the user has marked as excluded (e.g., via filtering). Per the API contract, "exclusions should apply after inclusions."
Previously, the Python extension ignored request.exclude entirely, causing "Run Tests" to run all tests even when the user had filtered the Test Explorer view. This fix adds exclude handling at two levels:
In getTestItemsForWorkspace(): Filter out excluded items before passing to the test adapter (checks ancestors for top-level items)
In WorkspaceTestAdapter.executeTests(): Pre-expand the exclude set to include all descendants, then pass to getTestCaseNodes() which skips excluded nodes with O(1) set lookups during traversal
Also adds a visited set to getTestCaseNodes() to avoid expanding the same node multiple times when includes contains overlapping items.
Fixes the issue where filtering tests in Test Explorer (e.g., by tag) and clicking "Run Tests" would still run all tests.
Fixes #25742