@@ -144,6 +144,50 @@ def test_for_invalid_template(client):
144
144
)
145
145
146
146
147
+ @pytest .mark .django_project (
148
+ extra_settings = """
149
+ TEMPLATE_LOADERS = (
150
+ 'django.template.loaders.filesystem.Loader',
151
+ 'django.template.loaders.app_directories.Loader',
152
+ )
153
+ TEMPLATES[0]["OPTIONS"]["string_if_invalid"] = "Something clever"
154
+ """
155
+ )
156
+ def test_invalid_template_variable_behaves_normally_when_ignored (
157
+ django_pytester : DjangoPytester
158
+ ) -> None :
159
+ django_pytester .create_app_file (
160
+ "<div>{{ invalid_var }}</div>" , "templates/invalid_template_base.html"
161
+ )
162
+ django_pytester .create_app_file (
163
+ "{% include 'invalid_template_base.html' %}" , "templates/invalid_template.html"
164
+ )
165
+ django_pytester .create_test_module (
166
+ """
167
+ from django.template.loader import render_to_string
168
+
169
+ import pytest
170
+
171
+ @pytest.mark.ignore_template_errors
172
+ def test_ignore(client):
173
+ assert render_to_string('invalid_template.html') == "<div>Something clever</div>"
174
+
175
+ def test_for_invalid_template(client):
176
+ render_to_string('invalid_template.html')
177
+
178
+ """
179
+ )
180
+ result = django_pytester .runpytest_subprocess ("-s" , "--fail-on-template-vars" )
181
+
182
+ origin = "'*/tpkg/app/templates/invalid_template_base.html'"
183
+ result .stdout .fnmatch_lines_random (
184
+ [
185
+ "tpkg/test_the_test.py .F*" ,
186
+ f"E * Failed: Undefined template variable 'invalid_var' in { origin } " ,
187
+ ]
188
+ )
189
+
190
+
147
191
@pytest .mark .django_project (
148
192
extra_settings = """
149
193
TEMPLATE_LOADERS = (
0 commit comments