Skip to content

Commit 8abe427

Browse files
committed
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)`. pytest-dev/pytest#5412
1 parent 04c1c35 commit 8abe427

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

tests/app/celery/test_ftp_update_tasks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_update_letter_notifications_statuses_raises_for_invalid_format(notify_a
4646

4747
with pytest.raises(DVLAException) as e:
4848
update_letter_notifications_statuses(filename='NOTIFY-20170823160812-RSP.TXT')
49-
assert 'DVLA response file: {} has an invalid format'.format('NOTIFY-20170823160812-RSP.TXT') in str(e)
49+
assert 'DVLA response file: {} has an invalid format'.format('NOTIFY-20170823160812-RSP.TXT') in str(e.value)
5050

5151

5252
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,
7575
failed = ["ref-foo"]
7676
assert "DVLA response file: {filename} has failed letters with notification.reference {failures}".format(
7777
filename="failed.txt", failures=failed
78-
) in str(e)
78+
) in str(e.value)
7979

8080

8181
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
136136
assert failed_letter.billable_units == 2
137137
assert failed_letter.updated_at
138138
assert "DVLA response file: {filename} has failed letters with notification.reference {failures}".format(
139-
filename="NOTIFY-20170823160812-RSP.TXT", failures=[format(failed_letter.reference)]) in str(e)
139+
filename="NOTIFY-20170823160812-RSP.TXT", failures=[format(failed_letter.reference)]) in str(e.value)
140140

141141

142142
def test_update_letter_notifications_does_not_call_send_callback_if_no_db_entry(notify_api, mocker,

tests/app/celery/test_letters_pdf_tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ def test_process_letter_task_check_virus_scan_failed(sample_letter_notification,
686686
with pytest.raises(VirusScanError) as e:
687687
process_virus_scan_failed(filename)
688688

689-
assert "Virus scan failed:" in str(e)
689+
assert "Virus scan failed:" in str(e.value)
690690
mock_move_failed_pdf.assert_called_once_with(filename, ScanErrorType.FAILURE)
691691
assert sample_letter_notification.status == NOTIFICATION_VIRUS_SCAN_FAILED
692692

tests/app/clients/test_mmg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def test_send_sms_raises_if_mmg_fails_to_return_json(notify_api, mocker):
104104
request_mock.post('https://example.com/mmg', text=response_dict, status_code=200)
105105
mmg_client.send_sms(to, content, reference)
106106

107-
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
107+
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
108108
assert exc.value.status_code == 200
109109
assert exc.value.text == 'NOT AT ALL VALID JSON {"key" : "value"}}'
110110

tests/app/dao/test_services_dao.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ def test_dao_fetch_live_services_data(sample_user):
503503
def test_get_service_by_id_returns_none_if_no_service(notify_db):
504504
with pytest.raises(NoResultFound) as e:
505505
dao_fetch_service_by_id(str(uuid.uuid4()))
506-
assert 'No row was found for one()' in str(e)
506+
assert 'No row was found for one()' in str(e.value)
507507

508508

509509
def test_get_service_by_id_returns_service(notify_db_session):

0 commit comments

Comments
 (0)