          for middleware_path in settings.MIDDLEWARE_CLASSES:
              mw_class = import_string(middleware_path)
              try:
                  mw_instance = mw_class()
              except MiddlewareNotUsed:
                  continue
  
              if hasattr(mw_instance, 'process_request'):
                  request_middleware.append(mw_instance.process_request)
              if hasattr(mw_instance, 'process_view'):
 
</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 that piece of middleware from the middleware process.
 </s> add 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.
            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)
          for middleware_path in settings.MIDDLEWARE_CLASSES:
              mw_class = import_string(middleware_path)
              try:
                  mw_instance = mw_class()
            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)
                  continue
  
              if hasattr(mw_instance, 'process_request'):
                  request_middleware.append(mw_instance.process_request)
              if hasattr(mw_instance, 'process_view'):
keep keep keep keep replace keep keep keep keep keep
 Fixed #14664 -- Logged a warning if MiddlewareNotUsed is raised in DEBUG mode. 
django/core/handlers/base.py