forked from reactive-python/reactpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
66 lines (51 loc) · 1.64 KB
/
conftest.py
File metadata and controls
66 lines (51 loc) · 1.64 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from __future__ import annotations
import pytest
from _pytest.config.argparsing import Parser
from reactpy.config import (
REACTPY_ASYNC_RENDERING,
REACTPY_DEBUG,
REACTPY_TESTS_DEFAULT_TIMEOUT,
)
from reactpy.testing import (
BackendFixture,
DisplayFixture,
capture_reactpy_logs,
)
from reactpy.testing.display import _playwright_visible
from . import pytestmark # noqa: F401
REACTPY_ASYNC_RENDERING.set_current(True)
REACTPY_DEBUG.set_current(True)
def pytest_addoption(parser: Parser) -> None:
parser.addoption(
"--visible",
dest="visible",
action="store_true",
help="Open a browser window when running web-based tests",
)
@pytest.fixture(scope="session")
async def display(server, browser):
async with DisplayFixture(backend=server, browser=browser) as display:
yield display
@pytest.fixture(scope="session")
async def server():
async with BackendFixture() as server:
yield server
@pytest.fixture(scope="session")
async def browser(pytestconfig: pytest.Config):
from playwright.async_api import async_playwright
async with async_playwright() as pw:
async with await pw.chromium.launch(
headless=not _playwright_visible(pytestconfig),
timeout=REACTPY_TESTS_DEFAULT_TIMEOUT.current * 1000,
) as browser:
yield browser
@pytest.fixture(autouse=True)
def assert_no_logged_exceptions():
with capture_reactpy_logs() as records:
yield
try:
for r in records:
if r.exc_info is not None:
raise r.exc_info[1]
finally:
records.clear()