File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -294,6 +294,8 @@ def cleanup(self, cause: str = None) -> None:
294294 # To prevent 'Future exception was never retrieved' we ignore all callbacks that are no_reply.
295295 if callback .no_reply :
296296 continue
297+ if callback .future .cancelled ():
298+ continue
297299 callback .future .set_exception (self ._closed_error )
298300 self ._callbacks .clear ()
299301 self .emit ("close" )
Original file line number Diff line number Diff line change 1313# limitations under the License.
1414import asyncio
1515import gc
16+ import sys
1617from typing import Dict
1718
1819import pytest
1920
20- from playwright .async_api import async_playwright
21+ from playwright .async_api import Page , async_playwright
2122from tests .server import Server
2223from tests .utils import TARGET_CLOSED_ERROR_MESSAGE
2324
@@ -67,3 +68,22 @@ async def test_cancel_pending_protocol_call_on_playwright_stop(server: Server) -
6768 with pytest .raises (Exception ) as exc_info :
6869 await pending_task
6970 assert TARGET_CLOSED_ERROR_MESSAGE in str (exc_info .value )
71+
72+
73+ async def test_should_not_throw_with_taskgroup (page : Page ) -> None :
74+ if sys .version_info < (3 , 11 ):
75+ pytest .skip ("TaskGroup is only available in Python 3.11+" )
76+
77+ from builtins import ExceptionGroup # type: ignore
78+
79+ async def raise_exception () -> None :
80+ raise ValueError ("Something went wrong" )
81+
82+ with pytest .raises (ExceptionGroup ) as exc_info :
83+ async with asyncio .TaskGroup () as group : # type: ignore
84+ group .create_task (page .locator (".this-element-does-not-exist" ).inner_text ())
85+ group .create_task (raise_exception ())
86+ assert len (exc_info .value .exceptions ) == 1
87+ assert "Something went wrong" in str (exc_info .value .exceptions [0 ])
88+ assert isinstance (exc_info .value .exceptions [0 ], ValueError )
89+ assert await page .evaluate ("() => 11 * 11" ) == 121
You can’t perform that action at this time.
0 commit comments