66from django .urls import reverse
77from pytest_django .asserts import assertHTMLEqual , assertNumQueries
88from pytest_django .fixtures import SettingsWrapper
9- from pytest_subtests import SubTests
109
1110
12- RENDERED_VIEWS = [
11+ parameters = [
1312 (
1413 "homepage.html" ,
1514 5 ,
9493]
9594
9695
96+ @pytest .mark .parametrize (
97+ ["filename" , "num_queries" , "url" ],
98+ parameters ,
99+ ids = [
100+ "homepage" ,
101+ "version-detail.html" ,
102+ "module-detail.html" ,
103+ "klass-detail.html" ,
104+ "klass-detail-old.html" ,
105+ "fuzzy-module-detail.html" ,
106+ "fuzzy-klass-detail.html" ,
107+ "fuzzy-klass-detail-old.html" ,
108+ ],
109+ )
97110@pytest .mark .django_db
98111def test_page_html (
99- client : Client , settings : SettingsWrapper , subtests : SubTests
112+ client : Client ,
113+ settings : SettingsWrapper ,
114+ filename : str ,
115+ num_queries : int ,
116+ url : str ,
100117) -> None :
101118 """
102119 Checks that the pages in the array above match the reference files in tests/_page_snapshots/.
@@ -118,22 +135,20 @@ def test_page_html(
118135 # ValueError: Missing staticfiles manifest entry for 'bootstrap.css'
119136 settings .STATICFILES_STORAGE = None
120137
121- for filename , num_queries , url in RENDERED_VIEWS :
122- with subtests .test (url = url ):
123- with assertNumQueries (num_queries ):
124- response = client .get (url )
138+ with assertNumQueries (num_queries ):
139+ response = client .get (url )
125140
126- html = response .rendered_content
127- path = Path ("tests/_page_snapshots" , filename )
141+ html = response .rendered_content
142+ path = Path ("tests/_page_snapshots" , filename )
128143
129- # Uncomment the below to re-generate the reference files
130- # when they need to change for a legitimate reason.
131- # DO NOT commit this uncommented!
132- # path.write_text(html)
144+ # Uncomment the below to re-generate the reference files when they need to
145+ # change for a legitimate reason.
146+ # DO NOT commit this uncommented!
147+ # path.write_text(html)
133148
134- expected = path .read_text ()
149+ expected = path .read_text ()
135150
136- # This forces a useful error in the case of a mismatch.
137- # We have to ignore the type because accessing __wrapped__ is pretty odd.
138- assertHTMLEqual .__wrapped__ .__self__ .maxDiff = None # type: ignore
139- assertHTMLEqual (html , expected )
151+ # This forces a useful error in the case of a mismatch.
152+ # We have to ignore the type because accessing __wrapped__ is pretty odd.
153+ assertHTMLEqual .__wrapped__ .__self__ .maxDiff = None # type: ignore
154+ assertHTMLEqual (html , expected )
0 commit comments