  
  It's sometimes useful to determine at run-time whether a piece of middleware
  should be used. In these cases, your middleware's ``__init__`` method may
  raise :exc:`django.core.exceptions.MiddlewareNotUsed`. Django will then remove
  that piece of middleware from the middleware process.
  
  Guidelines
  ----------
  
  * Middleware classes don't have to subclass anything.
 
</s> remove from django.test import TestCase, override_settings
 </s> add from django.test import RequestFactory, TestCase, override_settings
from django.test.utils import patch_logger </s> remove             except MiddlewareNotUsed:
 </s> add             except MiddlewareNotUsed as exc:
                if settings.DEBUG:
                    if six.text_type(exc):
                        logger.debug('MiddlewareNotUsed(%r): %s', middleware_path, exc)
                    else:
                        logger.debug('MiddlewareNotUsed: %r', middleware_path)
that piece of middleware from the middleware process and a debug message will
be logged to the ``django.request`` logger when :setting:`DEBUG` is set to
``True``.

.. versionchanged:: 1.8

    Previously, :exc:`~django.core.exceptions.MiddlewareNotUsed` exceptions
    weren't logged.
  
  It's sometimes useful to determine at run-time whether a piece of middleware
  should be used. In these cases, your middleware's ``__init__`` method may
  raise :exc:`django.core.exceptions.MiddlewareNotUsed`. Django will then remove
that piece of middleware from the middleware process and a debug message will
be logged to the ``django.request`` logger when :setting:`DEBUG` is set to
``True``.

.. versionchanged:: 1.8

    Previously, :exc:`~django.core.exceptions.MiddlewareNotUsed` exceptions
    weren't logged.
  
  Guidelines
  ----------
  
  * Middleware classes don't have to subclass anything.
keep keep keep keep replace keep keep keep keep keep
 Fixed #14664 -- Logged a warning if MiddlewareNotUsed is raised in DEBUG mode. 
docs/topics/http/middleware.txt