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

オープン 初心者向け
#3,360 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
65/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
backend

調査の方向性

レポートの再現スクリプトをローカル checkout に対して実行して現在の失敗を確認し、次に sync API が listener コールバックを dispatch する場所と、listener の例外が捕捉される場所を確認してください。レポートはそれをその catch 節に絞り込んでいます。その節は Exception を処理しており、BaseException のサブクラス(pytest.fail()、pytest.skip()、pytest.xfail() が送出するものなど)を対象に含める必要がありますが、接続を kill しないままにする必要もあります。完了とは、実行が 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分
マージ済み PR(30日)
53

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/playwright-python のほかの issue

microsoft/playwright-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。