title: Django tests are not outputting Messages in template rendering
body: <p>I can't seem to get a unit test to check if Messages are rendering properly in my template.  As per my template, I'm not getting any output where the messages should be listed.</p>
  <p>I'm using pytest 6.2.5 and Django 3.1.13 if that's helpful. Here is my test code:</p>
  <pre><code>import pytest
  from django.contrib import messages
  from django.contrib.messages.middleware import MessageMiddleware
  from django.contrib.sessions.middleware import SessionMiddleware
  from django.test import RequestFactory
  from django.views.generic import TemplateView
  
  pytestmark = pytest.mark.django_db
  
  class TestBaseTemplate:
      def test_messages_middleware(self):
          request = RequestFactory().get(&quot;/&quot;)
          view = TemplateView.as_view(template_name=&quot;base.html&quot;)
  
          middleware1 = SessionMiddleware()
          middleware1.process_request(request)
          request.session.save()
  
          middleware2 = MessageMiddleware()
          middleware2.process_request(request)
  
          foobar_msg = &quot;Hello, world!&quot;
          messages.info(request, foobar_msg)
  
          request.session.save()
          response = view(request)
  
          response.render()
          content = response.content.decode(&quot;utf-8&quot;)
  
          # This assert fails
          assert foobar_msg in content 
  </code></pre>
  <p>My message block in the template (base.html) is straight-forward (and does work in views that send messages):</p>
  <pre><code>  {% if messages %}
    &lt;div&gt;
      {% for message in messages %}
      &lt;p&gt;{{ message }}&lt;/p&gt;
      {% endfor %}
    &lt;/div&gt;
    {% endif %}
  </code></pre>
  <p>I can see through debugging that before you get to rendering the response that the &quot;Hello, world!&quot; message is being noted properly in the request via the Session/Message middleware, it's just not being rendered in the response.</p>
  <p>Any ideas on what I'm missing?  Do I need to do something with a context preprocessor before rendering the content?</p>
  <p>Thanks in advance for any advice!</p>