首页 > 解决方案 > 使用当前正在运行的服务器测试 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但找不到应用它的方法。

标签: pythonpython-requestsodoo

解决方案


推荐阅读