Skip to content

Commit 07c43dc

Browse files
authored
Merge pull request #248 from classy-python/remove-subtests
Use pytest's parametrize instead of subtests
2 parents 996ee58 + fbc55d0 commit 07c43dc

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

requirements.dev.in

-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ mypy-json-report>=0.1.3
77
pre-commit
88
pytest
99
pytest-django
10-
pytest-subtests
1110
types-requests

requirements.dev.txt

-3
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@ pytest==7.1.2
5050
# via
5151
# -r requirements.dev.in
5252
# pytest-django
53-
# pytest-subtests
5453
pytest-django==4.5.2
5554
# via -r requirements.dev.in
56-
pytest-subtests==0.8.0
57-
# via -r requirements.dev.in
5855
python-dateutil==2.8.2
5956
# via faker
6057
pyyaml==6.0.1

tests/test_page_snapshots.py

+33-18
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
from django.urls import reverse
77
from pytest_django.asserts import assertHTMLEqual, assertNumQueries
88
from pytest_django.fixtures import SettingsWrapper
9-
from pytest_subtests import SubTests
109

1110

12-
RENDERED_VIEWS = [
11+
parameters = [
1312
(
1413
"homepage.html",
1514
5,
@@ -94,9 +93,27 @@
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
98111
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,
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

Comments
 (0)