Skip to content

Enhance pytest installation flow and error handling with Environment Extension integration #25252

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

Merged
merged 9 commits into from
Jul 10, 2025

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jul 8, 2025

Overview

This PR addresses the issue where pytest configuration attempts would proceed without user confirmation when pytest is not installed, and provides better error messages when pytest installation issues occur.

Changes Made

1. Enhanced User Prompt for pytest Installation

Before: Extension would silently attempt to install pytest without user input.

After: Shows a user-friendly prompt when pytest is selected but not installed:

pytest selected but not installed. Would you like to install pytest?
[Install pytest] [Ignore]

2. Python Environments Extension Integration

When the Python Environments extension is available:

  • Uses the managePackages API for proper environment-targeted installation
  • Ensures pytest is installed in the correct Python environment
  • Provides better integration with the extension ecosystem

New Class: PytestInstallationHelper handles the enhanced installation flow with fallback to traditional installer when the environment extension is not available.

Technical Implementation

  • New: src/client/testing/configuration/pytestInstallationHelper.ts - Handles enhanced installation flow
  • Enhanced: src/client/testing/configuration/pytest/testConfigurationManager.ts - Integrates new installation helper
  • Enhanced: src/client/testing/testController/common/utils.ts - Improved error message detection
  • Comprehensive test coverage with unit tests for all scenarios

Fixes #25251.
also fixes #17772

Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] pytest not installed but selected for configuration updates Enhance pytest installation flow and error handling with Environment Extension integration Jul 8, 2025
@Copilot Copilot AI requested a review from eleanorjboyd July 8, 2025 16:42
Copilot finished work on behalf of eleanorjboyd July 8, 2025 16:42
@eleanorjboyd eleanorjboyd added the debt Covers everything internal: CI, testing, refactoring of the codebase, etc. label Jul 8, 2025
@eleanorjboyd eleanorjboyd marked this pull request as ready for review July 8, 2025 20:10
@eleanorjboyd eleanorjboyd added skip tests Updates to tests unnecessary skip package*.json package.json and package-lock.json don't both need updating and removed skip tests Updates to tests unnecessary labels Jul 8, 2025
@vs-code-engineering vs-code-engineering bot added this to the July 2025 milestone Jul 8, 2025
@anthonykim1
Copy link

I see that we show the notification pop-up suggesting Pytest when configuring test for new repo.
Did we also wanted to edit what shows up in pytest Discvoery Error?
Screenshot 2025-07-09 at 11 47 09 AM

Copy link
Author

Copilot AI commented Jul 9, 2025

I see that we show the notification pop-up suggesting Pytest when configuring test for new repo.
Did we also wanted to edit what shows up in pytest Discvoery Error?
<img width="1722" alt="Screens...

Yes, I've enhanced the "pytest Discovery Error" message to be more user-friendly and actionable!

The discovery error now shows:

  • Before: "pytest Discovery Error" with only "Show output" link
  • After: "pytest Not Installed" with "Install pytest | Show output" when pytest is not installed

This provides the same user-friendly experience as the configuration flow, allowing users to install pytest directly from the discovery error message. The implementation includes:

  1. Added python.installPytest command that uses the existing PytestInstallationHelper
  2. Enhanced error messages to include installation link when pytest is not installed
  3. Automatically refreshes test data after successful installation

Commit: 3d371b1

Copilot finished work on behalf of anthonykim1 July 9, 2025 19:04
@eleanorjboyd
Copy link
Member

I don't think so- the error message is still relevant and has a different lifetime so I think its good as is

@eleanorjboyd
Copy link
Member

@copilot can you switch the popup that asks the user if they want to install pytest (if they have the environments extension) to a modal so it takes up the whole screen and is more "in your face" to the user.

Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
Copy link
Author

Copilot AI commented Jul 9, 2025

@copilot can you switch the popup that asks the user if they want to install pytest (if they have the environments extension) to a modal so it takes up the whole screen and is more "in your face" to t...

Done! The pytest installation prompt now shows as a modal dialog instead of a popup notification. This makes it more prominent and requires explicit user action before they can continue. Commit: 272c601

Copilot finished work on behalf of eleanorjboyd July 9, 2025 20:34
@anthonykim1
Copy link

Screenshot 2025-07-09 at 2 02 25 PM
Looks fine other than lint fails

Co-authored-by: anthonykim1 <62267334+anthonykim1@users.noreply.github.com>
Copy link
Author

Copilot AI commented Jul 9, 2025

Screenshot 2025-07-09 at 2 02 25 PM
Looks fine other than lint fails

Fixed the formatting issues in the test files. The lint failure was due to prettier formatting requirements for long method calls. Commit: f752cb1

Copilot finished work on behalf of anthonykim1 July 9, 2025 21:12
@eleanorjboyd eleanorjboyd enabled auto-merge (squash) July 10, 2025 22:10
@eleanorjboyd eleanorjboyd merged commit 81f3397 into main Jul 10, 2025
85 checks passed
@eleanorjboyd eleanorjboyd deleted the copilot/fix-25251 branch July 10, 2025 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
debt Covers everything internal: CI, testing, refactoring of the codebase, etc. skip package*.json package.json and package-lock.json don't both need updating skip-issue-check
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve feedback when user tries a pytest test when pytest is not installed, but is selected as the testing library
4 participants