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
Browsersub-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:
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
browserfixture. Specify the language in the browser scenario or use thelanguagesparameter of theset_browserdecorator instead.Note
You must also use the
languagefixture 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
browserfixture. When thedjangoextra is installed, tests automatically run with all configured languages.Note
You must also use the
languagefixture in your test when applying this decorator.
timezone
The django extra also provides the timezone fixture:
You may control the time zone for a specific test with the set_timezone decorator: