Skip to content

Conversation

@eleanorjboyd
Copy link
Member

@eleanorjboyd eleanorjboyd commented Nov 14, 2025

Plan: Add Location to TestClass Items for Run Functionality

This PR implements the fix for issue #25592 - TestClass items need a location (lineno) to be runnable and show the green arrow in VS Code's Test Explorer.

Changes Completed:

Pytest:

  • Update Python pytest adapter to add lineno field to class nodes

    • Modify create_class_node() in python_files/vscode_pytest/__init__.py to extract and include line number
    • Update TypeScript types to allow lineno on class nodes
    • Fix Python type checking errors
  • Update expected test outputs

    • Update all expected discovery outputs in python_files/tests/pytestadapter/expected_discovery_test_output.py to include lineno for class nodes
    • Add find_class_line_number() helper function

Unittest:

  • Update Python unittest adapter to add lineno field to class nodes

    • Modify build_test_tree() in python_files/unittestadapter/pvsc_utils.py to add line numbers
    • Add get_class_line() function to extract class line numbers
    • Make lineno optional field in TestNode TypedDict
    • Return empty string instead of "*" when line cannot be determined
  • Update expected test outputs

    • Update expected discovery outputs in python_files/tests/unittestadapter/expected_discovery_test_output.py to include lineno for class nodes
    • Add find_class_line_number() helper function

TypeScript:

  • Update TypeScript result resolver
    • Modify populateTestTree() in src/client/testing/testController/common/utils.ts to handle lineno for class nodes
    • Update type definitions to allow optional lineno on DiscoveredTestNode
    • Add 'function' to DiscoveredTestType enum

Test Results:

Pytest tests: ✅ 13/15 passing (2 failures expected - pytest-describe plugin not installed)
Unittest tests: ✅ Verified class nodes include lineno

Code quality:

  • ✅ Ruff formatting and linting passed
  • ⚠️ Pyright has pre-existing errors (not introduced by this change)

Technical Implementation:

Pytest:

  • Extract line number from pytest.Class objects using Python's inspect.getsourcelines()
  • Add lineno as optional field to TestNode TypedDict (using NotRequired)
  • Return empty string when line number cannot be determined

Unittest:

  • Extract line number from test_case.class using inspect.getsourcelines()
  • Add lineno field to class nodes during tree building
  • Use same optional field pattern in TestNode TypedDict
  • Return empty string when line number cannot be determined (consistent with pytest)

TypeScript:

  • Create VS Code ranges for class nodes when lineno is present

This minimal change ensures TestClass items are treated similarly to test items in terms of having a location, making them runnable in the VS Code UI for both pytest and unittest.

Original prompt

fantastic analysis. Please implement this and keep in mind all this context you have; both how this should be done, what should be changed, and how tests are impacted

[Chronological Review: The conversation began with the user requesting a discussion about issue #25592 on GitHub, specifically regarding the need for TestClass items to have a location for proper functionality. The user then asked about the risks associated with this change and which tests would need updating. Following a positive response to the analysis, the user requested implementation of the discussed changes while considering the context of how it should be done, what should be changed, and how tests are impacted.]

[Intent Mapping:

  1. "lets talk about this issue: Support running (Python) test classes as a whole #25592 what needs to be done (likely) is TestClass items need a location so it shows as the green arrow and makes it runnable." - User wants to discuss the issue and create a plan for implementation.
  2. "what risk does this change have? what tests will need to be updated?" - User seeks to understand the implications of the changes and necessary test updates.
  3. "fantastic analysis. Please implement this and keep in mind all this context you have; both how this should be done, what should be changed, and how tests are impacted." - User requests implementation of the analysis with a focus on context and impact.]

[Technical Inventory:

[Code Archaeology: No specific files or code changes were discussed in detail, but the focus was on the functionality of TestClass items and their integration into the existing codebase.]

[Progress Assessment:

  • Completed Tasks: Analysis of the issue and identification of necessary changes.
  • Partially Complete Work: Implementation of the discussed changes is pending.
  • Validated Outcomes: None yet, as implementation has not been executed.]

[Context Validation: All critical information for continuation is captured, including the need for changes to TestClass items and the implications for testing.]

[Recent Commands Analysis:

  • Last Agent Commands: User requested a plan for the issue, an analysis of risks, and implementation of the discussed changes.
  • Tool Results Summary: No specific tool results were returned as the conversation focused on planning and analysis rather than executing code or commands.
  • Pre-Summary State: The agent was actively discussing the implementation of changes related to issue Support running (Python) test classes as a whole #25592 when the token budget was exceeded.
  • Operation Context: The commands were executed to align with the user's goals of addressing the issue and ensuring proper functionality of TestClass items.]
1. Conversation Overview: - Primary Objectives: The user aimed to discuss issue #25592, focusing on making TestClass items runnable by providing them with a location. The user also sought to understand the risks and necessary test updates related to this change. - Session Context: The conversation flowed from discussing the issue, analyzing risks, and finally requesting implementation of the proposed changes. - User Intent Evolution: The user transitioned from seeking information and analysis to requesting concrete implementation of the discussed changes.
  1. Technical Foundation:
  1. Codebase Status:
  • No specific files were modified or discussed in detail, but the focus was on the functionality of TestClass items.
  1. Problem Resolution:
  • Issues Encountered: The need for TestClass items to have a location for proper functionality.
  • Solutions Implemented: Analysis of the issue and identification of necessary changes were completed, but implementation is pending.
  • Debugging Context: No ongoing troubleshooting efforts were mentioned.
  • Lessons Learned: Understanding the implications of changes on existing functionality and tests is crucial.
  1. Progress Tracking:
  • Completed Tasks: Analysis of the issue and identification of necessary changes.
  • Partially Complete Work: Implementation of the discussed changes is pending.
  • Validated Outcomes: None yet, as implementation has not been executed.
  1. Active Work State:
  • Current Focus: The user was focused on implementing changes related to issue Support running (Python) test classes as a whole #25592.
  • Recent Context: The last few exchanges involved discussing the issue, analyzing risks, and planning for implementation.
  • Working Code: No specific code snippets were discussed recently.
  • Immediate Context: The specific problem being addressed was the need for TestClass items to have a locat...

Created from VS Code.

Copilot AI and others added 7 commits November 14, 2025 15:53
- Modified create_class_node() to extract and include line number using inspect.getsourcelines()
- Updated TypeScript types to allow optional lineno on DiscoveredTestNode
- Modified populateTestTree() to handle lineno for class nodes (not just test items)
- Added find_class_line_number() helper function for test expectations
- Updated all test expectations to include lineno for class nodes
- Added 'function' to DiscoveredTestType enum

This enables TestClass items to show the green arrow and be runnable in VS Code's Test Explorer.

Co-authored-by: eleanorjboyd <[email protected]>
- Added NotRequired to imports for optional TypedDict fields
- Made lineno an optional field in TestNode TypedDict
- Formatted Python files with ruff

Co-authored-by: eleanorjboyd <[email protected]>
- Modified build_test_tree() in pvsc_utils.py to add line numbers to class nodes
- Added get_class_line() function to extract class line numbers using inspect
- Made lineno an optional field in TestNode TypedDict
- Added find_class_line_number() helper for test expectations
- Updated expected test outputs to include lineno for class nodes

This implements the same functionality for unittest as was done for pytest, enabling TestClass items to show the green arrow and be runnable in VS Code's Test Explorer.

Co-authored-by: eleanorjboyd <[email protected]>
…ermined

Changed get_class_line() to return "" instead of "*" when inspect.getsourcelines() fails, making it consistent with the pytest implementation and leaving the field blank when the line number cannot be determined.

Co-authored-by: eleanorjboyd <[email protected]>
@eleanorjboyd eleanorjboyd added the skip tests Updates to tests unnecessary label Nov 15, 2025
@eleanorjboyd eleanorjboyd added the feature-request Request for new features or functionality label Nov 15, 2025
@eleanorjboyd eleanorjboyd marked this pull request as ready for review November 15, 2025 00:09
@vs-code-engineering vs-code-engineering bot added this to the November 2025 milestone Nov 15, 2025
@eleanorjboyd eleanorjboyd enabled auto-merge (squash) November 15, 2025 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature-request Request for new features or functionality skip tests Updates to tests unnecessary

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants