wsvincent / djangoforprofessionals

Source code for Django for Professionals 4.0
https://djangoforprofessionals.com/
MIT License
640 stars 264 forks source link

Home and About AssertTemplateUsed Tests Fail Starting In Chapter 16 #266

Open evdutt opened 1 year ago

evdutt commented 1 year ago

test_homepage_template and test_aboutpage_template both work in Ch15 but fail in Ch16 onwards.

Issues 74 and 33 seem to say the same thing. Using Django 4.2 and django-debug-toolbar 4.0.0. I therefore think something is going on with the debug toolbar "intercepting" somehow? The debug toolbar itself shows the templates being utilized, and they render just fine.

Printing out the response as a dict shows that truly the templates are not used in Ch16 onwards. Seems like this is probably not an issue with your code/book, but the interaction of AssertTemplateUsed and django-debug-toolbar.

HBarotov commented 5 months ago

Hi,

Kind of late to respond, but I think I found the solution.

In my case, the issue lies in caching. In the book, per-site caching is enabled. Try disabling caching in your django_project/setttings.py. Comment out cache middlewares and cache settings. Try running your tests and they should pass.

Or, if you don't want to disable caching during your tests, try adding

from django.core.cache import cache

class AboutPageTests(SimpleTestCase):
    def tearDown(self):
        cache.clear()

Here is the full link to SO discussion.