feat(testing): expose pytest marks as tags in Test Explorer#25740
feat(testing): expose pytest marks as tags in Test Explorer#25740andravin wants to merge 5 commits into
Conversation
|
@microsoft-github-policy-service agree |
|
Tested with v2026.0.0 because main has build issues. As pictured in the above screenshot, I created test file with |
|
For testers: A prebuilt VSIX is available at https://github.com/andravin/vscode-python/releases Install with: code --install-extension ms-python-insiders.vsixIf you prefer to build from source: git clone https://github.com/andravin/vscode-python.git
cd vscode-python
git checkout feature/pytest-marks-as-tags-release
npm install && npm run package
code --install-extension ms-python-insiders.vsixNote: This replaces the official Python extension. Uninstall and reinstall from the marketplace to revert. |
67107ef to
97ffb96
Compare
|
Tested against main. Unit tests have been added. |
Extract pytest marks (e.g., @pytest.mark.slow, @pytest.mark.integration) during test discovery and expose them as VS Code TestTags with IDs like "mark.slow", "mark.integration". This enables filtering tests by marks in the Test Explorer UI using @python-tests:mark.slow syntax. Changes: - Add tags field to TestItem TypedDict in pytest plugin - Extract marks from test_case.own_markers in create_test_node() - Add tags field to DiscoveredTestItem TypeScript type - Create TestTag objects from marks in populateTestTree() Fixes microsoft#20350 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Prevents duplicate tags when the same marker is applied multiple times or through plugin interactions. Uses dict.fromkeys() to preserve order while deduplicating. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add TypeScript unit tests verifying populateTestTree correctly converts tags to TestTag objects with mark. prefix, and handles empty/undefined tags. Add Python discovery test verifying mark extraction, deduplication, parametrize filtering, and tag ordering. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
fc70c4c to
7edd6e4
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds end-to-end support for exposing pytest marks (e.g. @pytest.mark.slow) as VS Code Test Explorer tags by extracting marks during pytest discovery (Python-side), carrying them through the discovery payload (shared types), and attaching them to TestItem.tags during tree population (TypeScript-side).
Changes:
- Extend pytest discovery payloads to include a
tagsfield on discovered test items, populated fromtest_case.own_markers(excludingparametrize, with deduplication). - Extend the shared TypeScript discovery types and update
populateTestTree()to convert those tags into VS Code tag IDs likemark.<name>. - Add coverage in both TS unit tests and Python discovery tests + fixtures for marked tests.
Show a summary per file
| File | Description |
|---|---|
| src/client/testing/testController/common/utils.ts | Maps discovered pytest tag strings into TestItem.tags entries with mark. prefix. |
| src/client/testing/testController/common/types.ts | Adds optional tags?: string[] to the discovered test item shape. |
| src/test/testing/testController/utils.unit.test.ts | Adds unit tests verifying populateTestTree() behavior for mark tags and empty/undefined tags. |
| python_files/vscode_pytest/init.py | Extracts pytest marks from collected items and emits them as a tags list on discovery test items. |
| python_files/tests/pytestadapter/test_discovery.py | Adds a discovery test to validate mark-to-tags behavior (including dedupe and excluding parametrize). |
| python_files/tests/pytestadapter/expected_discovery_test_output.py | Adds expected discovery tree output for the new marks fixture (including tags). |
| python_files/tests/pytestadapter/.data/test_marks.py | New fixture file containing marked/parametrized tests used by the discovery test. |
Review details
Comments suppressed due to low confidence (1)
src/test/testing/testController/utils.unit.test.ts:677
- The expected mark tags are asserted in
slowthenintegrationorder, but the Python discovery expectation for multiple marks isintegrationthenslow. If the extension preserves the discovery order (aspopulateTestTreecurrently does), this assertion should reflect that ordering to avoid failing when fed real discovery data.
assert.deepStrictEqual(mockTestItem.tags, [
RunTestTag,
DebugTestTag,
{ id: 'mark.slow' },
{ id: 'mark.integration' },
- Files reviewed: 7/7 changed files
- Comments generated: 2
- Review effort level: Low
| # This is the expected output for the test_marks.py file. | ||
| # └── test_marks.py | ||
| # └── test_with_single_mark (tags: ["slow"]) | ||
| # └── test_with_multiple_marks (tags: ["slow", "integration"]) | ||
| # └── test_with_no_marks (tags: []) |
| id_: 'test-marked-id', | ||
| lineno: 5, | ||
| runID: 'run-marked', | ||
| tags: ['slow', 'integration'], | ||
| }; |

Extract pytest marks (e.g., @pytest.mark.slow, @pytest.mark.integration) during test discovery and expose them as VS Code TestTags with IDs like "mark.slow", "mark.integration". This enables filtering tests by marks in the Test Explorer UI using @python-tests:mark.slow syntax.
Changes:
Fixes #20350