|
14 | 14 |
|
15 | 15 | import multiprocessing |
16 | 16 | import os |
| 17 | +import subprocess |
| 18 | +import sys |
| 19 | +import textwrap |
17 | 20 | from datetime import timedelta |
| 21 | +from pathlib import Path |
18 | 22 | from typing import Any, Callable, Dict |
19 | 23 |
|
20 | 24 | import pytest |
@@ -361,6 +365,40 @@ def test_should_return_proper_api_name_on_error(page: Page) -> None: |
361 | 365 | assert str(error).startswith("Page.evaluate:") |
362 | 366 |
|
363 | 367 |
|
| 368 | +def test_should_not_orphan_callback_on_non_serializable_params( |
| 369 | + browser_name: str, |
| 370 | + launch_arguments: Dict[str, Any], |
| 371 | + tmp_path: Path, |
| 372 | +) -> None: |
| 373 | + # Regression test for https://github.com/microsoft/playwright-python/issues/3165. |
| 374 | + # Run in a subprocess so "Future exception was never retrieved" on exit is visible on stderr. |
| 375 | + script = tmp_path / "orphan_callback.py" |
| 376 | + script.write_text( |
| 377 | + textwrap.dedent( |
| 378 | + f""" |
| 379 | + from playwright.sync_api import sync_playwright |
| 380 | +
|
| 381 | + with sync_playwright() as p: |
| 382 | + browser = p[{browser_name!r}].launch(**{launch_arguments!r}) |
| 383 | + page = browser.new_page() |
| 384 | + try: |
| 385 | + page.locator("asdf").highlight(style=object()) |
| 386 | + except TypeError: |
| 387 | + pass |
| 388 | + browser.close() |
| 389 | + """ |
| 390 | + ) |
| 391 | + ) |
| 392 | + result = subprocess.run( |
| 393 | + [sys.executable, str(script)], |
| 394 | + capture_output=True, |
| 395 | + text=True, |
| 396 | + timeout=60, |
| 397 | + ) |
| 398 | + assert result.returncode == 0, result.stderr |
| 399 | + assert "Future exception was never retrieved" not in result.stderr |
| 400 | + |
| 401 | + |
364 | 402 | def test_click_should_accept_timedelta_for_timeout(page: Page) -> None: |
365 | 403 | with pytest.raises(TimeoutError, match="Timeout 1ms exceeded"): |
366 | 404 | page.click("does-not-exist", timeout=timedelta(milliseconds=1)) |
0 commit comments