Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy don't my Django unittests know that MessageMiddleware is installed?
    primarykey
    data
    text
    <p>I'm working on a Django project and am writing unittests for it. However, in a test, when I try and log a user in, I get this error:</p> <pre><code>MessageFailure: You cannot add messages without installing django.contrib.messages.middleware.MessageMiddleware </code></pre> <p>Logging in on the actual site works fine -- and a login message is displayed using the MessageMiddleware.</p> <p>In my tests, if I do this:</p> <pre><code>from django.conf import settings print settings.MIDDLEWARE_CLASSES </code></pre> <p>Then it outputs this:</p> <pre><code>('django.middleware.cache.UpdateCacheMiddleware', 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.cache.FetchFromCacheMiddleware', 'debug_toolbar.middleware.DebugToolbarMiddleware') </code></pre> <p>Which appears to show the MessageMiddleware is installed when tests are run.</p> <p>Is there an obvious step I'm missing?</p> <p><strong>UPDATE</strong></p> <p>After suggestions below, it does look like it's a settings thing.</p> <p>I currently have <code>settings/__init__.py</code> like this:</p> <pre><code>try: from settings.development import * except ImportError: pass </code></pre> <p>and <code>settings/defaults.py</code> containing most of the standard settings (including <code>MIDDLEWARE_CLASSES</code>). And then <code>settings.development.py</code> overrides some of those defaults like this:</p> <pre><code>from defaults import * DEBUG = True # etc </code></pre> <p>It looks like my dev site itself works fine, using the development settings. But although the tests seem to load the settings OK (both defaults and development) <code>settings.DEBUG</code> is set to <code>False</code>. I don't know why, or whether that's the cause of the problem. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload