7

I'm aware that django test cases are done with DEBUG=False and TEMPLATE_DEBUG=False, and that I can change it to True for a specific function, using

from django.test.utils import override_settings

@override_settings(DEBUG=True)
def test_one_function(self):
    # This test should be failing and is not.
    # If I did not test manually I would'nt know !
    pass

But maybe there is a better, more generic solution that apply for eveything at once ?

I have an error in my template : I included another template and the link is broken. If I manually check with DEBUG=True I get a TemplateDoesNotExist error. But during my test case the url is rendered without the broken include, it does not throw an error, and the http_status is 200. I already tested the very generic included template somewhere else, so I don't want to add test to see if what is inside was rendered correctly. But I want to see rendering fails, that's what my test are for !

I tried to set TEMPLATE_STRING_IF_INVALID to an Exception (found here), but it does not seem to be working for a broken include.

Is there a way to make all rendering error raise en exception during tests, without breaking the django's design principle of not running test in debug ?

Community
  • 1
  • 1
Pierre.Sassoulas
  • 3,733
  • 3
  • 33
  • 48

2 Answers2

2

You can use --debug-mode to set DEBUG=True for all tests. Example:

$ ./manage.py test --debug-mode

Another solution is to wait for Django 2.1 (it is not released yet). Documentation promises that lost includes will not be silenced (see the end of include tag reference).

  • for those looking for reference to `include tag fix`: https://code.djangoproject.com/ticket/27175 – Qback Dec 12 '18 at 13:05
0

Your question is solved here

There is a difference between template missing and object missing, TEMPLATE_STRING_IF_INVALID is called when there is object missing in context

Rasovica
  • 239
  • 1
  • 4
  • 14