Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion playwright/_impl/waiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def settle(matched: bool) -> None:
if not promise.done():
promise.set_result(event_arg)

def fail(e: Exception) -> None:
def fail(e: BaseException) -> None:
emitter.remove_listener(event, listener)
if not promise.done():
promise.set_exception(e)
Expand All @@ -256,6 +256,9 @@ def run() -> Any:
async def continuation() -> None:
try:
settle(bool(await matched))
except asyncio.CancelledError as e:
fail(e)
raise
except Exception as e:
fail(e)

Expand Down
14 changes: 14 additions & 0 deletions tests/async/python/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

"""Python only: tests of behaviors that no upstream test covers."""

import asyncio
from typing import Any, AsyncGenerator, Dict

import pytest
Expand Down Expand Up @@ -59,6 +60,19 @@ async def predicate(response: Any) -> bool:
await page.evaluate("() => fetch('/digits/1.png')")


async def test_expect_response_should_propagate_async_predicate_cancellation(
page: Page, server: Server
) -> None:
await page.goto(server.EMPTY_PAGE)

async def predicate(response: Any) -> bool:
raise asyncio.CancelledError("Predicate cancelled")

with pytest.raises(asyncio.CancelledError, match="Predicate cancelled"):
async with page.expect_response(predicate):
await page.evaluate("() => fetch('/digits/1.png')")


async def test_expect_response_should_reject_when_sync_predicate_throws(
page: Page, server: Server
) -> None:
Expand Down