Skip to content

Commit edf7bef

Browse files
committed
test: skip playwright tests if browsers are not installed/launchable
1 parent 0f90e2c commit edf7bef

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

g2p/tests/test_studio.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414

1515
from datetime import datetime
1616
from random import sample
17-
from unittest import IsolatedAsyncioTestCase, main
17+
from unittest import IsolatedAsyncioTestCase, SkipTest, main
1818

1919
import socketio # type: ignore
20+
from playwright.async_api import Error as PlaywrightError # type: ignore
2021
from playwright.async_api import async_playwright, expect # type: ignore
2122

2223
from g2p.log import LOGGER
@@ -39,7 +40,10 @@ async def test_socket_connection(self):
3940

4041
async def test_sanity(self):
4142
async with async_playwright() as p:
42-
browser = await p.chromium.launch(channel="chrome", headless=True)
43+
try:
44+
browser = await p.chromium.launch(channel="chrome", headless=True)
45+
except PlaywrightError:
46+
raise SkipTest("Cannot launch browser, skipping playwright tests")
4347
page = await browser.new_page()
4448
await page.goto(f"http://127.0.0.1:{self.port}/docs")
4549
await page.wait_for_timeout(self.timeout_delay)
@@ -65,7 +69,10 @@ async def test_sanity(self):
6569

6670
async def test_switch_langs(self):
6771
async with async_playwright() as p:
68-
browser = await p.chromium.launch(channel="chrome", headless=True)
72+
try:
73+
browser = await p.chromium.launch(channel="chrome", headless=True)
74+
except PlaywrightError:
75+
raise SkipTest("Cannot launch browser, skipping playwright tests")
6976
page = await browser.new_page()
7077
await page.goto(f"http://127.0.0.1:{self.port}")
7178
await page.wait_for_timeout(self.timeout_delay)
@@ -155,7 +162,10 @@ def find_test_case(test_case, langs_to_test) -> int:
155162
LOGGER.info("Lauching async_playwright")
156163
async with async_playwright() as p:
157164
LOGGER.info(("L" if block == 0 else "Rel") + "aunching browser")
158-
browser = await p.chromium.launch(channel="chrome", headless=True)
165+
try:
166+
browser = await p.chromium.launch(channel="chrome", headless=True)
167+
except PlaywrightError:
168+
raise SkipTest("Cannot launch browser, skipping playwright tests")
159169
LOGGER.info("Loading page")
160170
page = await browser.new_page()
161171
await page.goto(

0 commit comments

Comments
 (0)