Skip to content

Commit 399107e

Browse files
committed
Attempting to fix a flaky .github/workflows/test-src.yml. All tests pass on local container but are intermittent on GitHub Actions
1 parent 598ff3a commit 399107e

File tree

1 file changed

+23
-31
lines changed

1 file changed

+23
-31
lines changed

tests/conftest.py

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,54 @@
1+
import os
12
import subprocess
23

34
import pytest
4-
from playwright.async_api import Browser, Page, async_playwright
5-
from reactpy.config import REACTPY_TESTING_DEFAULT_TIMEOUT
5+
from playwright.async_api import async_playwright
66
from reactpy.testing import BackendFixture, DisplayFixture
77

88
from .tooling import update_vscode_env
99

10+
GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS", "").lower() == "true"
1011

11-
@pytest.fixture(scope="session")
12-
def anyio_backend():
13-
return "asyncio"
1412

15-
16-
def pytest_addoption(parser: pytest.Parser) -> None:
13+
def pytest_addoption(parser) -> None:
1714
parser.addoption(
18-
"--headed",
19-
dest="headed",
15+
"--headless",
16+
dest="headless",
2017
action="store_true",
21-
help="Open a browser window when running web-based tests",
18+
help="Hide the browser window when running web-based tests",
2219
)
2320

2421

2522
def pytest_sessionstart(session):
2623
"""Rebuild the project before running the tests to get the latest JavaScript"""
27-
2824
# subprocess.run(["hatch", "build", "--clean"], check=True)
29-
3025
update_vscode_env(".env")
3126
subprocess.run(["playwright", "install", "chromium"], check=True)
3227

3328

3429
@pytest.fixture(scope="session")
35-
def display(server: BackendFixture, page: Page):
36-
# async with DisplayFixture(server, page) as display:
37-
# yield display
38-
39-
return DisplayFixture(server, page)
30+
async def display(backend, browser):
31+
async with DisplayFixture(backend, browser) as display_fixture:
32+
display_fixture.page.set_default_timeout(10000)
33+
yield display_fixture
4034

4135

4236
@pytest.fixture(scope="session")
43-
async def server():
44-
async with BackendFixture() as server:
45-
yield server
37+
async def backend():
38+
async with BackendFixture() as backend_fixture:
39+
yield backend_fixture
4640

4741

4842
@pytest.fixture(scope="session")
49-
async def page(browser: Browser):
50-
context = await browser.new_context(permissions=["clipboard-read", "clipboard-write"])
51-
pg = await context.new_page()
52-
pg.set_default_timeout(REACTPY_TESTING_DEFAULT_TIMEOUT.current * 1000)
53-
try:
54-
yield pg
55-
finally:
56-
await pg.close()
43+
async def browser(pytestconfig):
44+
async with async_playwright() as pw:
45+
browser = await pw.chromium.launch(headless=True if GITHUB_ACTIONS else pytestconfig.getoption("headless"))
46+
context = await browser.new_context(permissions=["clipboard-read", "clipboard-write"])
47+
yield context
48+
await context.close()
49+
await browser.close()
5750

5851

5952
@pytest.fixture(scope="session")
60-
async def browser(pytestconfig: pytest.Config):
61-
async with async_playwright() as pw:
62-
yield await pw.chromium.launch(headless=not bool(pytestconfig.option.headed))
53+
def anyio_backend():
54+
return "asyncio"

0 commit comments

Comments
 (0)