pytest Plugin¶
pytest plugin: UI assertions backed by LayoutLens.
Registered automatically via the pytest11 entry point when layoutlens is
installed. The deterministic assertions (assert_a11y, assert_layout)
run keyless — no API key, no LLM, fully reproducible — so they can gate CI on
any fork with no secrets. The LLM assertion (assert_ui) skips rather
than fails when no API key is configured, so the same suite runs everywhere.
Usage:
def test_landing_page(layoutlens):
layoutlens.assert_a11y("landing.html") # axe, keyless
layoutlens.assert_layout("landing.html", viewport="mobile") # keyless
layoutlens.assert_ui("landing.html", "Is the CTA above the fold?")
Options: --layoutlens-model (default gpt-4o-mini), --layoutlens-no-llm
(make assert_ui skip unconditionally — a fast, free, deterministic-only
CI lane).
- class layoutlens.pytest_plugin.LayoutLensFixture(config)[source]¶
Sync assertion helpers over a shared
LayoutLensclient.- Parameters:
config (pytest.Config)
- assert_a11y(source, compliance_level='AA', viewport='desktop')[source]¶
Assert the page has no axe-core WCAG violations (keyless).
- Parameters:
- Returns:
Successful deterministic accessibility result.
- Raises:
pytest.fail.Exception – Listing each violated rule, its impact, and the first affected selectors.
- Return type:
- assert_layout(source, viewport='desktop')[source]¶
Assert the deterministic layout scan measures no defects (keyless).
- Parameters:
- Returns:
Successful deterministic layout result.
- Raises:
pytest.fail.Exception – Listing each measured defect with its selector, measured values, and violated threshold.
- Return type:
- assert_ui(source, question, min_confidence=0.0, viewport='desktop')[source]¶
Assert the vision model answers
questionwith a leading “yes”.Skips (never fails) when
--layoutlens-no-llmis set or no API key is configured, so keyless environments still run the rest of the suite.- Parameters:
- Returns:
Successful model-backed analysis result.
- Raises:
pytest.fail.Exception – When the model answers “no” (or an unparseable answer), with the model’s reasoning attached.
- Return type: