-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconftest.py
47 lines (33 loc) · 1.32 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import subprocess
import pytest
from playwright.async_api import async_playwright
from reactpy.testing import BackendFixture, DisplayFixture
GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS", "").lower() == "true"
def pytest_addoption(parser) -> None:
parser.addoption(
"--headless",
dest="headless",
action="store_true",
help="Hide the browser window when running web-based tests",
)
def pytest_sessionstart(session):
"""Rebuild the project before running the tests to get the latest JavaScript"""
subprocess.run(["hatch", "build", "--clean"], check=True)
subprocess.run(["playwright", "install", "chromium"], check=True)
@pytest.fixture(scope="session")
async def display(backend, browser):
async with DisplayFixture(backend, browser) as display_fixture:
display_fixture.page.set_default_timeout(10000)
yield display_fixture
@pytest.fixture(scope="session")
async def backend():
async with BackendFixture() as backend_fixture:
yield backend_fixture
@pytest.fixture(scope="session")
async def browser(pytestconfig):
async with async_playwright() as pw:
yield await pw.chromium.launch(headless=True if GITHUB_ACTIONS else pytestconfig.getoption("headless"))
@pytest.fixture(scope="session")
def anyio_backend():
return "asyncio"