The e-mail backend is always reset in tests

Review Request #7562 — Created July 31, 2015 and submitted — Latest diff uploaded

Information

Review Board
release-2.0.x

Reviewers

Previously, if a test using the console_email_backend decorator
raised an exception, the e-mail backend would not be reset to the old
backend, causing other tests to fail. This is no longer the case.

Ran unit tests.

Tests that used this decorator that raised an exception caused other
tests to fail without this patch applied but did not with it applied.

Diff Revision 1 (Latest)

reviewboard/notifications/tests.py
reviewboard/notifications/tests.py
Revision 507ca13a68a2f905b193d82b10a42464c0d826e6 New Change
37 lines
def console_email_backend():
38
    """
38
    """
39
    old_backend = settings.EMAIL_BACKEND
39
    old_backend = settings.EMAIL_BACKEND
40
    settings.EMAIL_BACKEND = \
40
    settings.EMAIL_BACKEND = \
41
        'django.core.mail.backends.console.EmailBackend'
41
        'django.core.mail.backends.console.EmailBackend'
42

    
   
42

   

    
   
43
    try:
43
    yield
44
>>>>    yield
44

    
   
45
    finally:
45
    settings.EMAIL_BACKEND = old_backend
46
>>>>    settings.EMAIL_BACKEND = old_backend
46

    
   
47

   
47

    
   
48

   
48

    
   

   
49
class EmailTestHelper(object):
49
class EmailTestHelper(object):
50
    def assertValidRecipients(self, user_list, group_list=[]):
50
    def assertValidRecipients(self, user_list, group_list=[]):
51
        recipient_list = mail.outbox[0].to + mail.outbox[0].cc
51
        recipient_list = mail.outbox[0].to + mail.outbox[0].cc
52
        self.assertEqual(len(recipient_list), len(user_list) + len(group_list))
52
        self.assertEqual(len(recipient_list), len(user_list) + len(group_list))
53

    
   
53

   
1628 lines
Loading...