6
6
from django .urls import reverse
7
7
from pytest_django .asserts import assertHTMLEqual , assertNumQueries
8
8
from pytest_django .fixtures import SettingsWrapper
9
- from pytest_subtests import SubTests
10
9
11
10
12
- RENDERED_VIEWS = [
11
+ parameters = [
13
12
(
14
13
"homepage.html" ,
15
14
5 ,
94
93
]
95
94
96
95
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
+ )
97
110
@pytest .mark .django_db
98
111
def 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 ,
100
117
) -> None :
101
118
"""
102
119
Checks that the pages in the array above match the reference files in tests/_page_snapshots/.
@@ -118,22 +135,20 @@ def test_page_html(
118
135
# ValueError: Missing staticfiles manifest entry for 'bootstrap.css'
119
136
settings .STATICFILES_STORAGE = None
120
137
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 )
125
140
126
- html = response .rendered_content
127
- path = Path ("tests/_page_snapshots" , filename )
141
+ html = response .rendered_content
142
+ path = Path ("tests/_page_snapshots" , filename )
128
143
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)
133
148
134
- expected = path .read_text ()
149
+ expected = path .read_text ()
135
150
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