Skip to content

Commit 1ca0611

Browse files
committed
Use some panel test util
1 parent ad9002b commit 1ca0611

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

tests/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import asyncio
2+
3+
import pytest
4+
5+
6+
@pytest.fixture
7+
def asyncio_loop():
8+
loop = asyncio.new_event_loop()
9+
asyncio.set_event_loop(asyncio.new_event_loop())
10+
yield
11+
loop.stop()
12+
loop.close()

tests/test_anywidget.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import time
2-
31
import anywidget
42
import panel as pn
53
import traitlets
6-
from panel.io.server import serve
7-
from playwright.sync_api import expect, Page
4+
from panel.tests.util import serve_and_wait
5+
from playwright.sync_api import Page, expect
86

97

108
class CounterWidget(anywidget.AnyWidget):
@@ -33,7 +31,7 @@ class CounterWidget(anywidget.AnyWidget):
3331
count = traitlets.Int(default_value=0).tag(sync=True)
3432

3533

36-
def test_anywidget(page: Page) -> None:
34+
def test_anywidget(page: Page, asyncio_loop) -> None:
3735
"""Test anywidget button counter example."""
3836
# Port to run the panel server on.
3937
port = 5006
@@ -44,8 +42,7 @@ def test_anywidget(page: Page) -> None:
4442

4543
# Serve the button using panel, the time delay is necessary for panel to start and
4644
# serve the widget.
47-
serve(panels=panels, port=port, show=False)
48-
time.sleep(0.2)
45+
serve_and_wait(panels, port=port)
4946

5047
# Go to the page and locate the widget using playwright.
5148
page.goto(f"http://localhost:{port}")

0 commit comments

Comments
 (0)