@@ -113,6 +113,71 @@ def test_ignore(client):
113113 )
114114
115115
116+ @pytest .mark .django_project (
117+ extra_settings = """
118+ TEMPLATE_LOADERS = (
119+ 'django.template.loaders.filesystem.Loader',
120+ 'django.template.loaders.app_directories.Loader',
121+ )
122+ ROOT_URLCONF = 'tpkg.app.urls'
123+ """
124+ )
125+ def test_invalid_template_variable2 (django_testdir ):
126+ django_testdir .create_app_file (
127+ """
128+ from django.conf.urls import url
129+ from pytest_django_test.compat import patterns
130+
131+ from tpkg.app import views
132+
133+ urlpatterns = patterns(
134+ '',
135+ url(r'the_view/', views.the_view),
136+ )
137+ """ ,
138+ "urls.py" ,
139+ )
140+ django_testdir .create_app_file (
141+ """
142+ from django.shortcuts import render
143+
144+
145+ def the_view(request):
146+ return render(
147+ request=request,
148+ template_name='the_template.html',
149+ context={'data': {'empty': '', 'none': None}},
150+ )
151+ """ ,
152+ "views.py" ,
153+ )
154+ django_testdir .create_app_file (
155+ """
156+ <div>{{ data.empty|default:'d' }}</div>
157+ <div>{{ data.none|default:'d' }}</div>
158+ <div>{{ data.empty|default_if_none:'d' }}</div>
159+ <div>{{ data.none|default_if_none:'d' }}</div>
160+ <div>{{ data.missing|default_if_none:'d' }}</div>
161+ """ ,
162+ "templates/the_template.html" ,
163+ )
164+ django_testdir .create_test_module (
165+ """
166+ import pytest
167+
168+ def test_for_invalid_template(client):
169+ client.get('/the_view/')
170+ """
171+ )
172+ result = django_testdir .runpytest_subprocess ("-s" , "--fail-on-template-vars" )
173+ result .stdout .fnmatch_lines_random (
174+ [
175+ "tpkg/test_the_test.py F" ,
176+ "E * Failed: Undefined template variable 'data.missing' in *the_template.html'" ,
177+ ]
178+ )
179+
180+
116181@pytest .mark .django_project (
117182 extra_settings = """
118183 TEMPLATE_LOADERS = (
0 commit comments