diff --git a/python_files/vscode_pytest/__init__.py b/python_files/vscode_pytest/__init__.py index 89565dab1264..935a83360fdd 100644 --- a/python_files/vscode_pytest/__init__.py +++ b/python_files/vscode_pytest/__init__.py @@ -56,6 +56,7 @@ class TestItem(TestData): lineno: str runID: str + tags: list[str] class TestNode(TestData): @@ -816,6 +817,14 @@ def create_test_node( str(test_case.location[1] + 1) if (test_case.location[1] is not None) else "" ) absolute_test_id = get_absolute_test_id(test_case.nodeid, get_node_path(test_case)) + + # Extract pytest marks as tags + tags: list[str] = [] + if hasattr(test_case, "own_markers"): + for marker in test_case.own_markers: + if marker.name and marker.name != "parametrize": + tags.append(marker.name) + return { "name": test_case.name, "path": get_node_path(test_case), @@ -823,6 +832,7 @@ def create_test_node( "type_": "test", "id_": absolute_test_id, "runID": absolute_test_id, + "tags": tags, } diff --git a/src/client/testing/testController/common/types.ts b/src/client/testing/testController/common/types.ts index 6121b3e24442..783b2b307d54 100644 --- a/src/client/testing/testController/common/types.ts +++ b/src/client/testing/testController/common/types.ts @@ -190,6 +190,7 @@ export type DiscoveredTestCommon = { export type DiscoveredTestItem = DiscoveredTestCommon & { lineno: number | string; runID: string; + tags?: string[]; }; export type DiscoveredTestNode = DiscoveredTestCommon & { diff --git a/src/client/testing/testController/common/utils.ts b/src/client/testing/testController/common/utils.ts index 606865e5ad7e..8594dcb40973 100644 --- a/src/client/testing/testController/common/utils.ts +++ b/src/client/testing/testController/common/utils.ts @@ -227,7 +227,10 @@ export function populateTestTree( if (!token?.isCancellationRequested) { if (isTestItem(child)) { const testItem = testController.createTestItem(child.id_, child.name, Uri.file(child.path)); - testItem.tags = [RunTestTag, DebugTestTag]; + + // Create tags from pytest marks (if available) and combine with default tags + const pytestMarkTags = (child.tags ?? []).map((tag) => ({ id: `mark.${tag}` })); + testItem.tags = [RunTestTag, DebugTestTag, ...pytestMarkTags]; let range: Range | undefined; if (child.lineno) { @@ -242,7 +245,6 @@ export function populateTestTree( } testItem.canResolveChildren = false; testItem.range = range; - testItem.tags = [RunTestTag, DebugTestTag]; testRoot!.children.add(testItem); // add to our map