[Regression]: pytest.fail() inside an event handler closes the connection
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
針對本地 checkout 執行報告中的重現腳本,以確認目前的失敗,然後查看 sync API 在哪裡分發 listener callback,以及 listener 的 exception 在哪裡被捕捉。報告將其縮小到那個 catch 子句:它處理 Exception,並且需要涵蓋 BaseException 的子類別,例如 pytest.fail()、pytest.skip() 和 pytest.xfail() 拋出的那些,同時仍然不殺掉連線。完成意味著執行會印出 1 Failed console: hi,error listener 仍會觸發,並且之後頁面仍然可用;在現有 listener-error 測試旁邊新增一個回歸測試。
由索引模型根據 Issue 內容生成。
描述
Last Good Version
1.64.0
First Bad Version
1.65.0
Steps to reproduce
import pytest
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
page = p.chromium.launch().new_page()
page.on("error", lambda e: print("error listener:", e))
page.on("console", lambda msg: pytest.fail(f"console: {msg.text}"))
for i in range(2):
try:
page.evaluate("console.log('hi')")
print(i, "ok")
except BaseException as e:
print(i, type(e).__name__, str(e).splitlines()[0])
Expected behavior
Same as 1.64:
0 ok
1 Failed console: hi
Actual behavior
0 TargetClosedError Page.evaluate: Target page, context or browser has been closed
1 TargetClosedError Playwright connection closed
The Failed is gone and the connection is dead. The error listener is not called either.
With a plain Exception (e.g. assert False) it still works, so it's only BaseException subclasses — which is what pytest.fail(), pytest.skip() and pytest.xfail() raise. The listener error handling in the dispatch path now catches Exception; before the port it was BaseException.
Additional context
No response
Environment
- Operating System: macOS 27.2
- CPU: arm64
- Browser: Chromium
- Python Version: 3.14
- Other info: sync API
- 主要語言
- Python
- 星號
- 15.1k
- 分支
- 1.3k
- 平均合併
- 6 小時 16 分鐘
- 30 天內合併 PR
- 53
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
microsoft/playwright-python 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 74/100
microsoft/playwright-python#3361 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 62/100
microsoft/playwright-python#3362 ·
維護者通常 1 天內回覆
查看 microsoft/playwright-python 的全部 Issue
相似的 Issue
-
難度 1/5 1 小時以內 新手友好度 88/100
snap-stanford/Biomni#380 ·
-
documentation priority: low size: S status: needs triage
難度 2/5 1-3 小時 新手友好度 74/100
cubrid-lab/sqlalchemy-cubrid#1397 ·
維護者通常 1 天內回覆
-
documentation priority: low size: S status: needs triage
難度 2/5 1-3 小時 新手友好度 72/100
cubrid-lab/pycubrid#1307 ·
維護者通常 1 天內回覆
-
[Bug]: Installer hides SSL certificate errors as bare URLError, and the suggested fix can't work未關閉bug
難度 2/5 1-3 小時 新手友好度 80/100
ShaftHQ/chaosengine-harness#143 ·
維護者通常 1 天內回覆
-
bug high-severity
難度 2/5 1-3 小時 新手友好度 72/100
aws/bedrock-agentcore-sdk-python#752 ·
維護者通常 1 天內回覆