From 4f839cf6d66e89d05baf562074538f633e2c867e Mon Sep 17 00:00:00 2001 From: Katie Smith Date: Thu, 31 Oct 2019 15:38:44 +0000 Subject: [PATCH] [#299] Fix tests which call str() on exception messages Since Pytest 5, `ExceptionInfo` objects (returned by `pytest.raises`) now have the same `str` representation as `repr`. This means that `str(e)` now needs to be changed to `str(e.value)`. https://github.com/pytest-dev/pytest/issues/5412 --- tests/app/celery/test_ftp_update_tasks.py | 6 +++--- tests/app/celery/test_letters_pdf_tasks.py | 2 +- tests/app/clients/test_mmg.py | 2 +- tests/app/dao/test_services_dao.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/app/celery/test_ftp_update_tasks.py b/tests/app/celery/test_ftp_update_tasks.py index 0607ce9b19..a431486545 100644 --- a/tests/app/celery/test_ftp_update_tasks.py +++ b/tests/app/celery/test_ftp_update_tasks.py @@ -46,7 +46,7 @@ def test_update_letter_notifications_statuses_raises_for_invalid_format(notify_a with pytest.raises(DVLAException) as e: update_letter_notifications_statuses(filename='NOTIFY-20170823160812-RSP.TXT') - assert 'DVLA response file: {} has an invalid format'.format('NOTIFY-20170823160812-RSP.TXT') in str(e) + assert 'DVLA response file: {} has an invalid format'.format('NOTIFY-20170823160812-RSP.TXT') in str(e.value) def test_update_letter_notification_statuses_when_notification_does_not_exist_updates_notification_history( @@ -75,7 +75,7 @@ def test_update_letter_notifications_statuses_raises_dvla_exception(notify_api, failed = ["ref-foo"] assert "DVLA response file: {filename} has failed letters with notification.reference {failures}".format( filename="failed.txt", failures=failed - ) in str(e) + ) in str(e.value) def test_update_letter_notifications_statuses_calls_with_correct_bucket_location(notify_api, mocker): @@ -136,7 +136,7 @@ def test_update_letter_notifications_statuses_persisted(notify_api, mocker, samp assert failed_letter.billable_units == 2 assert failed_letter.updated_at assert "DVLA response file: {filename} has failed letters with notification.reference {failures}".format( - filename="NOTIFY-20170823160812-RSP.TXT", failures=[format(failed_letter.reference)]) in str(e) + filename="NOTIFY-20170823160812-RSP.TXT", failures=[format(failed_letter.reference)]) in str(e.value) def test_update_letter_notifications_does_not_call_send_callback_if_no_db_entry(notify_api, mocker, diff --git a/tests/app/celery/test_letters_pdf_tasks.py b/tests/app/celery/test_letters_pdf_tasks.py index f64482f674..09d06aaadc 100644 --- a/tests/app/celery/test_letters_pdf_tasks.py +++ b/tests/app/celery/test_letters_pdf_tasks.py @@ -672,7 +672,7 @@ def test_process_letter_task_check_virus_scan_failed(sample_letter_notification, with pytest.raises(VirusScanError) as e: process_virus_scan_failed(filename) - assert "Virus scan failed:" in str(e) + assert "Virus scan failed:" in str(e.value) mock_move_failed_pdf.assert_called_once_with(filename, ScanErrorType.FAILURE) assert sample_letter_notification.status == NOTIFICATION_VIRUS_SCAN_FAILED diff --git a/tests/app/clients/test_mmg.py b/tests/app/clients/test_mmg.py index 8b8000328a..8752d8cbec 100644 --- a/tests/app/clients/test_mmg.py +++ b/tests/app/clients/test_mmg.py @@ -104,7 +104,7 @@ def test_send_sms_raises_if_mmg_fails_to_return_json(notify_api, mocker): request_mock.post('https://example.com/mmg', text=response_dict, status_code=200) mmg_client.send_sms(to, content, reference) - assert 'app.clients.sms.mmg.MMGClientResponseException: Code 200 text NOT AT ALL VALID JSON {"key" : "value"}} exception Expecting value: line 1 column 1 (char 0)' in str(exc) # noqa + assert 'Code 200 text NOT AT ALL VALID JSON {"key" : "value"}} exception Expecting value: line 1 column 1 (char 0)' in str(exc.value) # noqa assert exc.value.status_code == 200 assert exc.value.text == 'NOT AT ALL VALID JSON {"key" : "value"}}' diff --git a/tests/app/dao/test_services_dao.py b/tests/app/dao/test_services_dao.py index 0537caad57..fb0e97eba7 100644 --- a/tests/app/dao/test_services_dao.py +++ b/tests/app/dao/test_services_dao.py @@ -459,7 +459,7 @@ def test_dao_fetch_live_services_data(sample_user): def test_get_service_by_id_returns_none_if_no_service(notify_db): with pytest.raises(NoResultFound) as e: dao_fetch_service_by_id(str(uuid.uuid4())) - assert 'No row was found for one()' in str(e) + assert 'No row was found for one()' in str(e.value) def test_get_service_by_id_returns_service(notify_db_session):