Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
evdutt opened this issue May 4, 2023 · 1 comment
Open

Comments

@evdutt
Copy link

evdutt commented May 4, 2023

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
Copy link

HBarotov commented Jun 24, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants