From c04d6eac43c53b49c78120efcd7d950fd70541a7 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Sun, 30 Jun 2019 19:08:52 -0700 Subject: [PATCH] Update pytest (#6768) * Update pytest to 5.x * Ensure test de-monkeypatches auth on failure * Fix pytest.raises compat issue --- requirements/requirements-testing.txt | 4 ++-- tests/authentication/test_authentication.py | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/requirements/requirements-testing.txt b/requirements/requirements-testing.txt index 152ca7169..83ec9ab9e 100644 --- a/requirements/requirements-testing.txt +++ b/requirements/requirements-testing.txt @@ -1,4 +1,4 @@ # Pytest for running the tests. -pytest>=4.5.0,<4.6 -pytest-django>=3.4.8,<3.5 +pytest>=5.0,<5.1 +pytest-django>=3.5.1,<3.6 pytest-cov>=2.7.1 diff --git a/tests/authentication/test_authentication.py b/tests/authentication/test_authentication.py index 927989028..37e265e17 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 exc_info: + auth.authenticate_credentials('foo', 'bar') + assert 'User inactive or deleted.' in str(exc_info.value) + finally: + authentication.authenticate = old_authenticate @override_settings(ROOT_URLCONF=__name__,