python - 使用当前正在运行的服务器测试 python 请求
问题描述
请求调用不响应 localhost 中当前正在运行的服务器。
我有一个这样的脚本:
import requests
params = {
'access_token': 'access_token'
}
response = requests.get('http://localhost/something', params=params)
我在启动 localhost 服务器并直接调用时正在运行
python test_code.py
但我想将它移到测试中,每次升级服务器时调用它。实际上它正在运行但卡在response = requests.get('http://localhost/something', params=params)
class TestAPI(common.TransactionCase):
def setUp(self):
super(TestAPI, self).setUp()
def test_request(self):
params = {
'access_token': 'access_token'
}
response = requests.get('http://localhost/something', params=params)
有什么方法可以实现,mock
或者我听说过mock
但找不到应用它的方法。
解决方案
推荐阅读
- javascript - 通过 API 将视频文件从本地驱动器保存/上传到 Azure Blob 存储?
- python - 如何使用协同过滤通过用户行为预测用户?
- c++ - 错误 C2976 'std::array':迁移到 VS 2019 后模板参数和其他参数太少
- wordpress - 从自定义页面调用时,Woocommerce 产品档案不显示任何内容
- kdb - 创建新目录 kdb+
- git - 您可以使用 Azure Devops Server repos 中的 ssh 进行 git clone 吗?
- javascript - node.js和python中相同问题解决方案的不同结果
- javascript - 在套件脚本 2.0 中加载保存的搜索时 search.run().getRange 出错
- html - Chrome浏览器计算错误的元素宽度
- c# - GMap.NET 我怎样才能做出准确的路由?