Fixtures

mocker

The default installation provides the mocker fixture via pytest-mock.

browser

The browser extra provides a new browser fixture:

pytest_logikal.browser.browser() logikal_browser.Browser

Yield a scenario-specific Browser sub-class instance.

Browser settings must be specified via the set_browser() decorator:

@pytest_logikal.browser.set_browser(scenarios: Scenario | list[Scenario], headless: bool = True) Callable[[Any], Any]

Apply the given scenarios to the browser() fixture.

Parameters:
  • scenarios – The scenarios to use.

  • headless – Whether to use a headless browser instance.

You can specify browser scenarios with this decorator as follows:

from logikal_browser import Browser, scenarios
from pytest_django.live_server_helper import LiveServer

from pytest_logikal.browser import set_browser


@set_browser(scenarios.desktop)
def test_single_scenario(browser: Browser, live_server: LiveServer) -> None:
    browser.get(live_server.url)
    browser.check()

You can also run your test in multiple scenarios:

from logikal_browser import Browser, scenarios
from pytest_django.live_server_helper import LiveServer

from pytest_logikal.browser import set_browser


@set_browser([
    scenarios.desktop,
    scenarios.mobile_l,
])
def test_multiple_scenarios(browser: Browser, live_server: LiveServer) -> None:
    browser.get(live_server.url)
    browser.check()

live_url

The django extra provides a new live_url fixture:

pytest_logikal.django.live_url(name: str | None, args: Sequence[Any] | None, kwargs: dict[str, Any] | None) str

Return the path to a URL.

Parameters:
  • name – The URL pattern name.

  • args – The URL arguments to use.

  • kwargs – The URL keyword arguments to use.

language

The django extra also provides the language fixture:

pytest_logikal.django.language(request: Any) Iterable[str]

Return the currently activated language.

You may control the language for a specific test with the set_language or all_languages decorators:

@pytest_logikal.django.set_language(*language_codes: str) Callable[[Any], Any]

Mark a test to run with each of the specified languages.

Parameters:

*language_codes – The language codes to use.

Note

You must also use the language fixture in your test when applying this decorator.

@pytest_logikal.django.all_languages Callable[[Any], Any]

Mark a test to run with every available language.

Note

You must also use the language fixture in your test when applying this decorator.

timezone

The django extra also provides the timezone fixture:

pytest_logikal.django.timezone(request: Any) Iterable[str]

Return the current time zone ID.

You may control the time zone for a specific test with the set_timezone decorator:

@pytest_logikal.django.set_timezone(*zone_ids: str) Callable[[Any], Any]

Mark a test to run with each of the specified time zones.

Parameters:

*zone_ids – The time zone IDs to use.

Note

You must also use the timezone fixture in your test when applying this decorator.