Skip to content

Conversation

@apuly
Copy link

@apuly apuly commented Nov 14, 2025

The general except around the pytest run was causing tests to run twice if the exception handling of pytest is disabled. From the comment in the code it seems the exception handling is only there for when reading the test IDs break, so it shouldn't be required around the pytest main call.

Disabling the exception handling can be practical for debugging tests, as this starts up the python debugger within vscode. Currently however, this requires manually patching the run_pytest_script.py, which needs to be re-done every vscode update.

fixes: #25656

The general `except` around the pytest run was causing tests to run twice if the exception handling of pytest is disabled.
From the comment in the code it seems the exception handling is only there for when reading the test IDs break, so it shouldn't be required around the pytest main call.

Disabling the exception handling can be practical for debugging tests, as this starts up the python debugger within vscode. Currently however, this requires manually patching the run_pytest_script.py, which needs to be re-done every vscode update.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an issue where pytest tests would run twice when pytest's exception handling is disabled (typically for debugging purposes). The fix moves the pytest.main() call from inside the try block to an else block, ensuring that exceptions from pytest tests themselves don't trigger the fallback re-run mechanism.

Key Changes:

  • Restructured the exception handling to use Python's try-except-else pattern
  • The pytest.main() call now executes only when test ID reading succeeds, not as part of the exception-prone code path

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@eleanorjboyd eleanorjboyd added the bug Issue identified by VS Code Team member as probable bug label Dec 12, 2025
@vs-code-engineering vs-code-engineering bot added this to the December / January 2026 milestone Dec 12, 2025
@eleanorjboyd eleanorjboyd enabled auto-merge (squash) December 12, 2025 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue identified by VS Code Team member as probable bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pytest re-run when an exception in a test occurs

3 participants