From 24c18fc3d6c54b7d1b3174ff8d1d778cb3e2dda3 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Sun, 30 Jun 2019 17:22:50 -0700 Subject: [PATCH] Ensure test de-monkeypatches auth on failure --- tests/authentication/test_authentication.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/authentication/test_authentication.py b/tests/authentication/test_authentication.py index 927989028..40df2cdc8 100644 --- a/tests/authentication/test_authentication.py +++ b/tests/authentication/test_authentication.py @@ -533,11 +533,13 @@ class BasicAuthenticationUnitTests(TestCase): is_active = False old_authenticate = authentication.authenticate authentication.authenticate = lambda **kwargs: MockUser() - auth = authentication.BasicAuthentication() - with pytest.raises(exceptions.AuthenticationFailed) as error: - auth.authenticate_credentials('foo', 'bar') - assert 'User inactive or deleted.' in str(error) - authentication.authenticate = old_authenticate + try: + auth = authentication.BasicAuthentication() + with pytest.raises(exceptions.AuthenticationFailed) as error: + auth.authenticate_credentials('foo', 'bar') + assert 'User inactive or deleted.' in str(error) + finally: + authentication.authenticate = old_authenticate @override_settings(ROOT_URLCONF=__name__,