How to make a test case unsuccessful if the django template has a rendering error that is without the slightest production glitch

I know that django test cases are executed using 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 general solution that applies immediately to eveything?

I have an error in my template: I have included another template and the link is not working. If I manually check with DEBUG = True, I get a TemplateDoesNotExist error. But during my test, the url is displayed without a broken include, it does not throw an error, and http_status is 200. I already tested the template with general shared inclusion elsewhere, so I don’t want to add a test to see what is inside was displayed right. But I want the rendering to fail, for which my test is!

I tried setting TEMPLATE_STRING_IF_INVALID to Exception (found here ), but it doesn't seem to work for a broken include.

Is there a way to make all the rendering errors raise raise an exception during tests without violating the django design principle, which does not trigger validation during debugging?

+5
source share
1 answer

Your question is resolved here.

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

0
source

Source: https://habr.com/ru/post/1258456/


All Articles