test_response.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:lets-do-dns 作者: Jitsusama 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号