Skip to content

Conversation

@andravin
Copy link

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:

  1. In getTestItemsForWorkspace(): Filter out excluded items before passing to the test adapter (checks ancestors for top-level items)

  2. 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

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:

1. In getTestItemsForWorkspace(): Filter out excluded items before
   passing to the test adapter (checks ancestors for top-level items)

2. 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.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test runs ignore TestRunRequest.exclude (filtered tests still run)

1 participant