forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add line number support for class nodes in pytest and unittest #25593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
eleanorjboyd
wants to merge
9
commits into
microsoft:main
Choose a base branch
from
eleanorjboyd:terrible-pike
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+159
−3
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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]>
cfce9b4 to
0d7a230
Compare
TylerLeonhardt
approved these changes
Nov 15, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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.
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
linenofield to class nodescreate_class_node()inpython_files/vscode_pytest/__init__.pyto extract and include line numberlinenoon class nodesUpdate expected test outputs
python_files/tests/pytestadapter/expected_discovery_test_output.pyto includelinenofor class nodesfind_class_line_number()helper functionUnittest:
Update Python unittest adapter to add
linenofield to class nodesbuild_test_tree()inpython_files/unittestadapter/pvsc_utils.pyto add line numbersget_class_line()function to extract class line numberslinenooptional field inTestNodeTypedDictUpdate expected test outputs
python_files/tests/unittestadapter/expected_discovery_test_output.pyto includelinenofor class nodesfind_class_line_number()helper functionTypeScript:
populateTestTree()insrc/client/testing/testController/common/utils.tsto handlelinenofor class nodeslinenoonDiscoveredTestNodeDiscoveredTestTypeenumTest Results:
Pytest tests: ✅ 13/15 passing (2 failures expected - pytest-describe plugin not installed)
Unittest tests: ✅ Verified class nodes include lineno
Code quality:
Technical Implementation:
Pytest:
inspect.getsourcelines()linenoas optional field to TestNode TypedDict (using NotRequired)Unittest:
inspect.getsourcelines()linenofield to class nodes during tree buildingTypeScript:
linenois presentThis 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:
[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:
[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:
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.- Technical Foundation:
- Repository: vscode-python
- Current Branch: supposed-spoonbill
- Default Branch: main
- Active Pull Request: support extra patching for doctest (support extra patching for doctest #25591)
- Codebase Status:
- No specific files were modified or discussed in detail, but the focus was on the functionality of TestClass items.
- 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.
- 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.
- 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.