Skip to content

fix(events): preserve pytest outcomes without closing the connection - #3366

Draft
microsoft-playwright-automation[bot] wants to merge 2 commits into
mainfrom
triage/3360/45158857993-1
Draft

microsoft-playwright-automation[bot] wants to merge 2 commits into
mainfrom
triage/3360/45158857993-1

Conversation

@microsoft-playwright-automation

Copy link
Copy Markdown
Contributor
  • Pytest outcomes inherit BaseException, so the event emitter and dispatch error boundary let them escape and stop the pipe reader. Handle these outcomes through the existing listener-error path without closing the connection.
  • Keep cancellation, interrupt, and exit exceptions unchanged. Extend test_console_repr to check handled and unhandled pytest failures and a subsequent successful API call.

Verified in Chromium, Firefox, and WebKit: the regression fails without the fix and passes with it; 119 sync and 80 async checks passed, with one existing skip per run. mypy playwright and full repository lint passed.

Fixes #3360

Triaged on macOS by the Playwright bot - agent run

Comment thread playwright/_impl/utils/tasks.py Outdated
T = TypeVar("T")

# Python only: these stop execution, unlike user errors such as pytest.fail().
CONTROL_FLOW_EXCEPTIONS = (

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why are we allow-listing exceptions here? Can we instead only pass-through some exceptions that we want to support, like pytest ones? If we need some kind of internal API for that, let's make one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Replaced the exclusion list with a shared helper that selects only Exception and pytest's failure, skip, and xfail classes. Other BaseException subclasses are no longer caught; the extended regression checks this, and no registration API is needed for pytest's existing classes.

Revised on macOS by the Playwright bot - agent run

@microsoft-playwright-automation

This comment has been minimized.

@microsoft-playwright-automation

Copy link
Copy Markdown
Contributor Author

Hi, I'm the Playwright bot and I addressed the review.

The listener-error path now catches only Exception and pytest's failure, skip, and xfail classes. Other BaseException subclasses are not caught. The shared helper does not import pytest and also works when pytest is imported after Playwright.

The regression passes on Chromium, Firefox, and WebKit. It fails without the fix; the added assertion for an unregistered BaseException also fails on the original PR. Neighbouring sync and async checks passed: 158 sync and 71 async, with one existing skip each. Full lint and mypy playwright passed. Lint used Python 3.13 because the pinned type checker cannot check Python 3.14's standard library. Linux and Windows were not tested.

Revised on macOS by the Playwright bot - agent run

@microsoft-playwright-automation microsoft-playwright-automation Bot added agent-review-done The Playwright bot run ended and removed agent-review labels Nov 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-review-done The Playwright bot run ended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Regression]: pytest.fail() inside an event handler closes the connection

1 participant