def test_properly_raises_correct_record_failure_on_related_method_error(
mocker, method, exception):
stub_error = HTTPError()
stub_raise_for_status = mocker.MagicMock(side_effect=stub_error)
stub_request = mocker.MagicMock(spec=requests.Request, method=method)
stub_response = mocker.MagicMock(
spec=requests.Response,
raise_for_status=stub_raise_for_status, request=stub_request)
class_to_mock = 'lets_do_dns.do_domain.response.{}'.format(
exception.__name__)
mock_record_failure = mocker.patch(
class_to_mock, return_value=exception)
with pytest.raises(exception):
Response(stub_response)
mock_record_failure.assert_called_once_with(stub_error)
评论列表
文章目录