From 407c6d264c05c64fabedc883e3be532f5dd46c7d Mon Sep 17 00:00:00 2001 From: Katie Smith Date: Wed, 22 Apr 2020 16:31:59 +0100 Subject: [PATCH] Fix assertion in test When using `with pytest.raises...` any assertions inside the `with` statement that occur below the line that raises the exception don't get called. It's not possible to check the response status_code / location in this test because an exception is raised before the response is returned. --- tests/app/main/views/test_find_users.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/tests/app/main/views/test_find_users.py b/tests/app/main/views/test_find_users.py index 7e8fce81a..1378a677c 100644 --- a/tests/app/main/views/test_find_users.py +++ b/tests/app/main/views/test_find_users.py @@ -255,20 +255,15 @@ def test_archive_user_shows_error_message_if_user_cannot_be_archived( ) == 'User can’t be removed from a service - check all services have another team member with manage_settings' -def test_archive_user_does_not_create_event_if_user_client_raises_exception( +def test_archive_user_does_not_create_event_if_user_client_raises_unexpected_exception( platform_admin_client, api_user_active, mocker, mock_events, ): - mock_user_client = mocker.patch('app.user_api_client.post', side_effect=Exception()) - with pytest.raises(Exception): - response = platform_admin_client.post( + platform_admin_client.post( url_for('main.archive_user', user_id=api_user_active.id) ) - assert response.status_code == 500 - assert response.location == url_for('main.user_information', user_id=api_user_active['id'], _external=True) - mock_user_client.assert_called_once_with('/user/{}/archive'.format(api_user_active['id']), data=None) - assert not mock_events.called + assert not mock_events.called