set expect timeout in its own fixture with autouse to guarantee it will be set before use

This commit is contained in:
Daniel 2023-12-07 19:34:52 +01:00
parent 755eb6268a
commit 10f5713d8d

View file

@ -23,6 +23,12 @@ def pytest_addoption(parser: Parser):
parser.addoption("--timeout", action="store", type=int, default=20_000) parser.addoption("--timeout", action="store", type=int, default=20_000)
@pytest.fixture(autouse=True)
def set_expect_timeout(request):
TIMEOUT = request.config.getoption("--timeout")
expect.set_options(timeout=TIMEOUT)
@pytest.fixture @pytest.fixture
def context(context: BrowserContext, request) -> BrowserContext: def context(context: BrowserContext, request) -> BrowserContext:
# note: because this has the existing context fixture as an argument, it is ensured # note: because this has the existing context fixture as an argument, it is ensured
@ -33,7 +39,6 @@ def context(context: BrowserContext, request) -> BrowserContext:
context.set_default_timeout(TIMEOUT) context.set_default_timeout(TIMEOUT)
context.set_extra_http_headers(LOCALE) context.set_extra_http_headers(LOCALE)
expect.set_options(timeout=TIMEOUT)
return context return context