Skip to content

Commit b7e8c4c

Browse files
committed
Fix test compatibility with pytest >= 9.1
Pytest 9.1 no longer accepts non-Collection iterables in parametrize. Wrap generator functions and itertools.product calls with list(). Also deduplicate the parametrize values in testLegacyQuoteAttribute. The character list had 6 duplicates between the "spec" prefix and the extended character ranges. With --strict (set in pytest.ini), pytest 9.1 enforces unique parametrization IDs and rejects them. Assisted-by: Claude Opus 4.6
1 parent fd4f032 commit b7e8c4c

4 files changed

Lines changed: 11 additions & 13 deletions

File tree

html5lib/tests/test_encoding.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def param_encoding():
8282
yield test[b'data'], test[b'encoding']
8383

8484

85-
@pytest.mark.parametrize("data, encoding", param_encoding())
85+
@pytest.mark.parametrize("data, encoding", list(param_encoding()))
8686
def test_parser_encoding(data, encoding):
8787
p = HTMLParser()
8888
assert p.documentEncoding is None
@@ -92,7 +92,7 @@ def test_parser_encoding(data, encoding):
9292
assert encoding == p.documentEncoding, errorMessage(data, encoding, p.documentEncoding)
9393

9494

95-
@pytest.mark.parametrize("data, encoding", param_encoding())
95+
@pytest.mark.parametrize("data, encoding", list(param_encoding()))
9696
def test_prescan_encoding(data, encoding):
9797
stream = _inputstream.HTMLBinaryInputStream(data, useChardet=False)
9898
encoding = encoding.lower().decode("ascii")

html5lib/tests/test_sanitizer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ def test_details_summary_allowed():
130130

131131

132132
@pytest.mark.parametrize("expected, input",
133-
(pytest.param(expected, input, id=id)
134-
for id, expected, input in param_sanitizer()))
133+
[pytest.param(expected, input, id=id)
134+
for id, expected, input in param_sanitizer()])
135135
def test_sanitizer(expected, input):
136136
parsed = parseFragment(expected)
137137
expected = serialize(parsed,

html5lib/tests/test_serializer.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,12 @@ def testSpecQuoteAttribute(c):
155155
test_serializer(input_, output_, options_)
156156

157157

158-
@pytest.mark.parametrize("c", list("\t\n\u000C\x20\r\"'=<>`"
159-
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n"
158+
@pytest.mark.parametrize("c", list("\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n"
160159
"\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15"
161160
"\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
162-
"\x20\x2f\x60\xa0\u1680\u180e\u180f\u2000"
163-
"\u2001\u2002\u2003\u2004\u2005\u2006\u2007"
164-
"\u2008\u2009\u200a\u2028\u2029\u202f\u205f"
165-
"\u3000"))
161+
"\x20\"'=<>/\x60\xa0\u1680\u180e\u180f"
162+
"\u2000\u2001\u2002\u2003\u2004\u2005\u2006"
163+
"\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000"))
166164
def testLegacyQuoteAttribute(c):
167165
input_ = [["StartTag", "http://www.w3.org/1999/xhtml", "span",
168166
[{"namespace": None, "name": "foo", "value": c}]]]
@@ -212,7 +210,7 @@ def param_serializer():
212210
yield test["input"], test["expected"], test.get("options", {})
213211

214212

215-
@pytest.mark.parametrize("input, expected, options", param_serializer())
213+
@pytest.mark.parametrize("input, expected, options", list(param_serializer()))
216214
def test_serializer(input, expected, options):
217215
encoding = options.get("encoding", None)
218216

html5lib/tests/test_treewalkers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def param_treewalker_six_mix():
8787
yield intext, expected, attrs, tree
8888

8989

90-
@pytest.mark.parametrize("intext, expected, attrs_to_add, tree", param_treewalker_six_mix())
90+
@pytest.mark.parametrize("intext, expected, attrs_to_add, tree", list(param_treewalker_six_mix()))
9191
def test_treewalker_six_mix(intext, expected, attrs_to_add, tree):
9292
"""tests what happens when we add attributes to the intext"""
9393
treeName, treeClass = tree
@@ -105,7 +105,7 @@ def test_treewalker_six_mix(intext, expected, attrs_to_add, tree):
105105
raise AssertionError("TreewalkerEditTest: %s\nExpected:\n%s\nReceived:\n%s" % (treeName, expected, output))
106106

107107

108-
@pytest.mark.parametrize("tree,char", itertools.product(sorted(treeTypes.items()), ["x", "\u1234"]))
108+
@pytest.mark.parametrize("tree,char", list(itertools.product(sorted(treeTypes.items()), ["x", "\u1234"])))
109109
def test_fragment_single_char(tree, char):
110110
expected = [
111111
{'data': char, 'type': 'Characters'}

0 commit comments

Comments
 (0)