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 | Iterable[Scenario], languages: Iterable[str] | None = None, headless: bool | None = None) Callable[[Any], Any]

Apply the given scenarios to the browser() fixture.

Parameters:
  • scenarios – The scenarios to use.

  • languages – The languages to use. Defaults to using the scenario languages.

  • headless – Whether to use a headless browser instance.

You can specify browser scenarios with this decorator as follows:

from pytest_logikal import Browser, scenarios, set_browser
from pytest_logikal.django import LiveURL


@set_browser(scenarios.desktop, languages=['en-us'])
def test_single_scenario(browser: Browser, live_url: LiveURL) -> None:
    browser.get(live_url())
    browser.check()

You can also run your test in multiple scenarios:

from pytest_logikal import Browser, scenarios, set_browser
from pytest_logikal.django import LiveURL


@set_browser([
    scenarios.desktop,
    scenarios.mobile_l,
])
def test_multiple_scenarios(browser: Browser, live_url: LiveURL) -> None:
    browser.get(live_url('index'))
    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.

Warning

This decorator should not be used together with the browser fixture. Specify the language in the browser scenario or use the languages parameter of the set_browser decorator instead.

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.

Warning

This decorator should not be used together with the browser fixture. When the django extra is installed, tests automatically run with all configured languages.

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.