Skip to content

Commit ebfb3fb

Browse files
gabalafoudrammock
authored andcommitted
Use pytest-regressions to mark expected a11y test failures (pydata#1501)
* Use pytest-regressions with a11y tests to mark expected failures * Update tests/test_a11y.py * frozen data class * Revert "frozen data class" This reverts commit 3b0c73e. --------- Co-authored-by: Daniel McCloy <[email protected]>
1 parent dabf8e3 commit ebfb3fb

File tree

35 files changed

+111
-65
lines changed

35 files changed

+111
-65
lines changed

.pre-commit-config.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ repos:
99
hooks:
1010
- id: prettier
1111
# Exclude the HTML, since it doesn't understand Jinja2
12-
# exclude also the webpack.congo.js file has it embed complete url dificult to prettify
13-
exclude: .+\.html|webpack\.config\.js
12+
# exclude also the webpack.config.js file has it embed complete url dificult to prettify
13+
# exclude the pytest-regressions folder tests/test_ally
14+
exclude: .+\.html|webpack\.config\.js|tests/test_a11y/
1415

1516
- repo: https://github.com/psf/black
1617
rev: 22.12.0

tests/test_a11y.py

+68-16
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
import pytest
1010

11-
from .utils.pretty_axe_results import pretty_axe_results
12-
1311
# Using importorskip to ensure these tests are only loaded if Playwright is installed.
1412
playwright = pytest.importorskip("playwright")
1513
from playwright.sync_api import Page, expect # noqa: E402
@@ -72,34 +70,88 @@ def url_base():
7270
process.wait()
7371

7472

73+
def fingerprint_violations(accessibility_page_scan_violations):
74+
"""Create a fingerprint of the Axe violations array.
75+
76+
https://playwright.dev/docs/accessibility-testing#using-snapshots-to-allow-specific-known-issues
77+
"""
78+
return [
79+
{
80+
"id": violation["id"],
81+
"help": violation["help"],
82+
"helpUrl": violation["helpUrl"],
83+
"targets": [node["target"] for node in violation["nodes"]],
84+
}
85+
for violation in accessibility_page_scan_violations
86+
]
87+
88+
7589
@pytest.mark.a11y
7690
@pytest.mark.parametrize("theme", ["light", "dark"])
7791
@pytest.mark.parametrize(
7892
"url_pathname,selector",
7993
[
80-
("/examples/kitchen-sink/admonitions.html", "#admonitions"),
81-
("/examples/kitchen-sink/api.html", "#api-documentation"),
94+
(
95+
"/examples/kitchen-sink/admonitions.html",
96+
"#admonitions",
97+
),
98+
(
99+
"/examples/kitchen-sink/api.html",
100+
"#api-documentation",
101+
),
82102
("/examples/kitchen-sink/blocks.html", "#blocks"),
83-
("/examples/kitchen-sink/generic.html", "#generic-items"),
84-
("/examples/kitchen-sink/images.html", "#images-figures"),
103+
(
104+
"/examples/kitchen-sink/generic.html",
105+
"#generic-items",
106+
),
107+
(
108+
"/examples/kitchen-sink/images.html",
109+
"#images-figures",
110+
),
85111
("/examples/kitchen-sink/lists.html", "#lists"),
86-
("/examples/kitchen-sink/structure.html", "#structural-elements"),
87-
("/examples/kitchen-sink/structure.html", "#structural-elements-2"),
112+
(
113+
"/examples/kitchen-sink/structure.html",
114+
"#structural-elements",
115+
),
116+
(
117+
"/examples/kitchen-sink/structure.html",
118+
"#structural-elements-2",
119+
),
88120
("/examples/kitchen-sink/tables.html", "#tables"),
89-
("/examples/kitchen-sink/typography.html", "#typography"),
121+
(
122+
"/examples/kitchen-sink/typography.html",
123+
"#typography",
124+
),
90125
("/examples/pydata.html", "#pydata-library-styles"),
91-
("/user_guide/theme-elements.html", "#theme-specific-elements"),
92-
("/user_guide/web-components.html", "#sphinx-design-components"),
93-
("/user_guide/extending.html", "#extending-the-theme"),
94-
("/user_guide/styling.html", "#theme-variables-and-css"),
126+
(
127+
"/user_guide/theme-elements.html",
128+
"#theme-specific-elements",
129+
),
130+
(
131+
"/user_guide/web-components.html",
132+
"#sphinx-design-components",
133+
),
134+
(
135+
"/user_guide/extending.html",
136+
"#extending-the-theme",
137+
),
138+
(
139+
"/user_guide/styling.html",
140+
"#theme-variables-and-css",
141+
),
95142
# Using one of the simplest pages on the site, select the whole page for
96143
# testing in order to effectively test repeated website elements like
97144
# nav, sidebars, breadcrumbs, footer
98145
("/user_guide/page-toc.html", ""),
99146
],
100147
)
101148
def test_axe_core(
102-
theme: str, url_base: str, url_pathname: str, selector: str, page: Page
149+
data_regression,
150+
theme: str,
151+
url_base: str,
152+
url_pathname: str,
153+
selector: str,
154+
page: Page,
103155
):
104156
"""Should have no Axe-core violations at the provided theme and page section."""
105157
# Load the page at the provided path
@@ -118,8 +170,8 @@ def test_axe_core(
118170
# the PyData Sphinx Theme documentation website.)
119171
results = page.evaluate("axe.run()" if selector == "" else f"axe.run('{selector}')")
120172

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

124176

125177
def test_version_switcher_highlighting(page: Page, url_base: str) -> None:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- help: Table header text should not be empty
2+
helpUrl: https://dequeuniversity.com/rules/axe/4.6/empty-table-header?application=axeAPI
3+
id: empty-table-header
4+
targets:
5+
- - thead > tr > th:nth-child(1)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- help: Table header text should not be empty
2+
helpUrl: https://dequeuniversity.com/rules/axe/4.6/empty-table-header?application=axeAPI
3+
id: empty-table-header
4+
targets:
5+
- - thead > tr > th:nth-child(1)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

tests/utils/pretty_axe_results.py

-47
This file was deleted.

0 commit comments

Comments
 (0)