def test_exception(self):
        # Create a request
        request = self.factory.get('/')
        request.user = self.user

        # Run middleware
        self.middleware.process_request(request)
        self.assertTrue(pre_save.has_listeners(LogEntry))  # The signal should be present before trying to disconnect it.
        self.middleware.process_exception(request, ValidationError("Test"))

        # Validate result
        self.assertFalse(pre_save.has_listeners(LogEntry))
The signal will be disconnected when an exception is raised.
dataset/ETHPy150Open jjkester/django-auditlog/src/auditlog_tests/tests.py/MiddlewareTest.test_exception