Skip to content

Commit c04d6ea

Browse files
authored
Update pytest (#6768)
* Update pytest to 5.x * Ensure test de-monkeypatches auth on failure * Fix pytest.raises compat issue
1 parent 82c2b5c commit c04d6ea

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

requirements/requirements-testing.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Pytest for running the tests.
2-
pytest>=4.5.0,<4.6
3-
pytest-django>=3.4.8,<3.5
2+
pytest>=5.0,<5.1
3+
pytest-django>=3.5.1,<3.6
44
pytest-cov>=2.7.1

tests/authentication/test_authentication.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,13 @@ class MockUser:
533533
is_active = False
534534
old_authenticate = authentication.authenticate
535535
authentication.authenticate = lambda **kwargs: MockUser()
536-
auth = authentication.BasicAuthentication()
537-
with pytest.raises(exceptions.AuthenticationFailed) as error:
538-
auth.authenticate_credentials('foo', 'bar')
539-
assert 'User inactive or deleted.' in str(error)
540-
authentication.authenticate = old_authenticate
536+
try:
537+
auth = authentication.BasicAuthentication()
538+
with pytest.raises(exceptions.AuthenticationFailed) as exc_info:
539+
auth.authenticate_credentials('foo', 'bar')
540+
assert 'User inactive or deleted.' in str(exc_info.value)
541+
finally:
542+
authentication.authenticate = old_authenticate
541543

542544

543545
@override_settings(ROOT_URLCONF=__name__,

0 commit comments

Comments
 (0)