尝试使用$http.get('http://localhost:3000/+' + $scope.myQuery).then(function(){
//...
});
中的patch
编写单元测试来验证我的自定义mock
错误处理程序,该错误处理程序在引发自定义错误之前记录错误,我无法获得自定义错误到urllib2
。 raise
中的日志行成功执行后,模拟的异常将始终为raise
。即我的测试代码正在寻找LoggingErrorHandler
,但令人惊讶的是,该功能仍会提升CustomError
。
测试代码:
urllib2.HTTPError
urllib2 HTTPError处理的自定义错误处理程序:
@raises(CustomError)
def test_404_error_logging(self):
''' not the copy and paste code; enough to give you an idea '''
http_error = urllib2.HTTPError("mock_url", 404, "Not Found", "mock_headers", None)
with patch('function.that.invokes.error.handler', side_effect=http_error):
test_client.get("bad url")
CustomError也是我们的自定义异常。