'Refs #19325'

@override_settings(ADMINS=((u'admin', u'admin@example.com'),), DEBUG=False)
def test_uses_custom_email_backend(self):

    message = u'All    work    and    no    play    makes    Jack    a    dull    boy'
    admin_email_handler = self.get_admin_email_handler(self.logger)
    mail_admins_called = {u'called': False}
    def my_mail_admins(*args, **kwargs):
        connection = kwargs[u'connection']
        self.assertIsInstance(connection, MyEmailBackend)
        mail_admins_called[u'called'] = True
    orig_mail_admins = mail.mail_admins
    orig_email_backend = admin_email_handler.email_backend
    mail.mail_admins = my_mail_admins
    admin_email_handler.email_backend = u'logging_tests.logconfig.MyEmailBackend'
    try:
        self.logger.error(message)
        self.assertTrue(mail_admins_called[u'called'])
    finally:
        mail.mail_admins = orig_mail_admins
        admin_email_handler.email_backend = orig_email_backend
