[Regression]: pytest.fail() inside an event handler closes the connection
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
针对本地 checkout 运行报告中的复现脚本,以确认当前的失败,然后查看 sync API 在哪里分发 listener 回调,以及 listener 的异常在哪里被捕获。报告将其缩小到那个 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 天内回复