  from django.core.signals import got_request_exception
  from django.http import HttpResponse
  from django.template.response import TemplateResponse
  from django.template import Template
  from django.test import TestCase, override_settings
  
  
  class TestException(Exception):
      pass
  
 
</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. </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)
from django.test import RequestFactory, TestCase, override_settings
from django.test.utils import patch_logger
  from django.core.signals import got_request_exception
  from django.http import HttpResponse
  from django.template.response import TemplateResponse
  from django.template import Template
from django.test import RequestFactory, TestCase, override_settings
from django.test.utils import patch_logger
  
  
  class TestException(Exception):
      pass
  
keep keep keep keep replace keep keep keep keep keep
 Fixed #14664 -- Logged a warning if MiddlewareNotUsed is raised in DEBUG mode. 
tests/middleware_exceptions/tests.py