Skip to content

Commit

Permalink
[#299] Fix tests which call str() on exception messages
Browse files Browse the repository at this point in the history
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
  • Loading branch information
klssmith authored and philherbert committed Dec 31, 2020
1 parent 3de0cc6 commit 4f839cf
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions tests/app/celery/test_ftp_update_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/app/celery/test_letters_pdf_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/app/clients/test_mmg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}'

Expand Down
2 changes: 1 addition & 1 deletion tests/app/dao/test_services_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 4f839cf

Please sign in to comment.