@@ -188,6 +188,50 @@ def test_for_invalid_template(client):
188
188
)
189
189
190
190
191
+ @pytest .mark .django_project (
192
+ extra_settings = """
193
+ TEMPLATE_LOADERS = (
194
+ 'django.template.loaders.filesystem.Loader',
195
+ 'django.template.loaders.app_directories.Loader',
196
+ )
197
+ """
198
+ )
199
+ def test_invalid_template_variable_object_does_not_exists_behaves_like_an_empty_string (
200
+ django_pytester : DjangoPytester
201
+ ) -> None :
202
+ django_pytester .create_app_file (
203
+ "<div>{% if object_exists %}This should not appear{% endif %}</div>" ,
204
+ "templates/invalid_template_base.html"
205
+ )
206
+ django_pytester .create_app_file (
207
+ "{% include 'invalid_template_base.html' %}" , "templates/invalid_template.html"
208
+ )
209
+ django_pytester .create_test_module (
210
+ """
211
+ from django.core.exceptions import ObjectDoesNotExist
212
+ from django.template.loader import render_to_string
213
+
214
+ import pytest
215
+
216
+ def fake_one_to_one_relation_missing():
217
+ raise ObjectDoesNotExist()
218
+
219
+ def test_ignore(client):
220
+ assert render_to_string(
221
+ 'invalid_template.html',
222
+ {"object_exists": fake_one_to_one_relation_missing},
223
+ ) == "<div></div>"
224
+ """
225
+ )
226
+ result = django_pytester .runpytest_subprocess ("-s" , "--fail-on-template-vars" )
227
+
228
+ result .stdout .fnmatch_lines_random (
229
+ [
230
+ "tpkg/test_the_test.py ." ,
231
+ ]
232
+ )
233
+
234
+
191
235
@pytest .mark .django_project (
192
236
extra_settings = """
193
237
TEMPLATE_LOADERS = (
0 commit comments