Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pytest-regressions to mark expected a11y test failures #1501

Merged
merged 5 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
Expand Up @@ -9,8 +9,9 @@ repos:
hooks:
- id: prettier
# Exclude the HTML, since it doesn't understand Jinja2
# exclude also the webpack.congo.js file has it embed complete url dificult to prettify
exclude: .+\.html|webpack\.config\.js
# exclude also the webpack.config.js file has it embed complete url dificult to prettify
# exclude the pytest-regressions folder tests/test_ally
exclude: .+\.html|webpack\.config\.js|tests/test_a11y/

- repo: https://github.com/psf/black
rev: 22.12.0
Expand Down
86 changes: 69 additions & 17 deletions tests/test_a11y.py
Expand Up @@ -8,11 +8,9 @@

import pytest

from .utils.pretty_axe_results import pretty_axe_results

# Using importorskip to ensure these tests are only loaded if Playwright is installed.
playwright = pytest.importorskip("playwright")
from playwright.sync_api import Page, expect # noqa: E402
from playwright.sync_api import Page, expect # NOQA: E402
gabalafou marked this conversation as resolved.
Show resolved Hide resolved
gabalafou marked this conversation as resolved.
Show resolved Hide resolved

# Important note: automated accessibility scans can only find a fraction of
# potential accessibility issues.
Expand Down Expand Up @@ -72,34 +70,88 @@ def url_base():
process.wait()


def fingerprint_violations(accessibility_page_scan_violations):
"""Create a fingerprint of the Axe violations array.

https://playwright.dev/docs/accessibility-testing#using-snapshots-to-allow-specific-known-issues
"""
return [
{
"id": violation["id"],
"help": violation["help"],
"helpUrl": violation["helpUrl"],
"targets": [node["target"] for node in violation["nodes"]],
}
for violation in accessibility_page_scan_violations
]


@pytest.mark.a11y
@pytest.mark.parametrize("theme", ["light", "dark"])
@pytest.mark.parametrize(
"url_pathname,selector",
[
("/examples/kitchen-sink/admonitions.html", "#admonitions"),
("/examples/kitchen-sink/api.html", "#api-documentation"),
(
"/examples/kitchen-sink/admonitions.html",
"#admonitions",
),
(
"/examples/kitchen-sink/api.html",
"#api-documentation",
),
Comment on lines +94 to +101
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these look like autoformatting changes; did our precommit hook do these? Wondering why they're only showing up now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm not sure why they weren't picked up before. Maybe I had an older version of the package when I first committed the file?

("/examples/kitchen-sink/blocks.html", "#blocks"),
("/examples/kitchen-sink/generic.html", "#generic-items"),
("/examples/kitchen-sink/images.html", "#images-figures"),
(
"/examples/kitchen-sink/generic.html",
"#generic-items",
),
(
"/examples/kitchen-sink/images.html",
"#images-figures",
),
("/examples/kitchen-sink/lists.html", "#lists"),
("/examples/kitchen-sink/structure.html", "#structural-elements"),
("/examples/kitchen-sink/structure.html", "#structural-elements-2"),
(
"/examples/kitchen-sink/structure.html",
"#structural-elements",
),
(
"/examples/kitchen-sink/structure.html",
"#structural-elements-2",
),
("/examples/kitchen-sink/tables.html", "#tables"),
("/examples/kitchen-sink/typography.html", "#typography"),
(
"/examples/kitchen-sink/typography.html",
"#typography",
),
("/examples/pydata.html", "#pydata-library-styles"),
("/user_guide/theme-elements.html", "#theme-specific-elements"),
("/user_guide/web-components.html", "#sphinx-design-components"),
("/user_guide/extending.html", "#extending-the-theme"),
("/user_guide/styling.html", "#theme-variables-and-css"),
(
"/user_guide/theme-elements.html",
"#theme-specific-elements",
),
(
"/user_guide/web-components.html",
"#sphinx-design-components",
),
(
"/user_guide/extending.html",
"#extending-the-theme",
),
(
"/user_guide/styling.html",
"#theme-variables-and-css",
),
# Using one of the simplest pages on the site, select the whole page for
# testing in order to effectively test repeated website elements like
# nav, sidebars, breadcrumbs, footer
("/user_guide/page-toc.html", ""),
],
)
def test_axe_core(
theme: str, url_base: str, url_pathname: str, selector: str, page: Page
data_regression,
gabalafou marked this conversation as resolved.
Show resolved Hide resolved
theme: str,
url_base: str,
url_pathname: str,
selector: str,
page: Page,
):
"""Should have no Axe-core violations at the provided theme and page section."""
# Load the page at the provided path
Expand All @@ -118,8 +170,8 @@ def test_axe_core(
# the PyData Sphinx Theme documentation website.)
results = page.evaluate("axe.run()" if selector == "" else f"axe.run('{selector}')")

# Expect Axe-core to have found 0 accessibility violations
assert len(results["violations"]) == 0, pretty_axe_results(results, selector)
# Check found violations against known violations that we do not plan to fix
data_regression.check(fingerprint_violations(results["violations"]))


def test_version_switcher_highlighting(page: Page, url_base: str) -> None:
Expand Down
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1,5 @@
- help: Table header text should not be empty
helpUrl: https://dequeuniversity.com/rules/axe/4.6/empty-table-header?application=axeAPI
id: empty-table-header
targets:
- - thead > tr > th:nth-child(1)
@@ -0,0 +1,5 @@
- help: Table header text should not be empty
helpUrl: https://dequeuniversity.com/rules/axe/4.6/empty-table-header?application=axeAPI
id: empty-table-header
targets:
- - thead > tr > th:nth-child(1)
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
@@ -0,0 +1 @@
[]
47 changes: 0 additions & 47 deletions tests/utils/pretty_axe_results.py

This file was deleted.