如何使Flask测试客户端具有与请求相同的接口?

如何使Flask测试客户端具有与请求相同的接口?,flask,testing,python-requests,Flask,Testing,Python Requests,如何编写能够在黑盒测试(远程网站)和白盒测试(本地运行的烧瓶应用程序)之间切换的烧瓶测试 我对此很感兴趣,因为我可以在本地和CI环境中设置这样的黑盒测试环境。我可以在本地设置白盒测试,但不能在CI环境中设置。所以我想从本地的白盒测试设置中获益,但我不想复制我的测试套件。如果客户机夹具与请求具有相同的交互,我会很高兴 我试过的 conftest.py import pytest import app import os import requests BASE_URL = "http:

如何编写能够在黑盒测试(远程网站)和白盒测试(本地运行的烧瓶应用程序)之间切换的烧瓶测试

我对此很感兴趣,因为我可以在本地和CI环境中设置这样的黑盒测试环境。我可以在本地设置白盒测试,但不能在CI环境中设置。所以我想从本地的白盒测试设置中获益,但我不想复制我的测试套件。如果
客户机
夹具与请求具有相同的交互,我会很高兴

我试过的 conftest.py

import pytest
import app
import os
import requests

BASE_URL = "http://staging.example.com"

@pytest.fixture
def client():
    if os.environ.get('WHITEBOX_TESTING'):
        app.app.config['TESTING'] = True

        with app.app.test_client() as client:
            yield client
    else:
        yield requests
test_.py

import pytest
import requests

from .conftest import BASE_URL


@pytest.mark.route
def test_route(client):
    resp = client.get(f"{BASE_URL}/api/")
    assert resp.status_code == 200

    # This does not work! It's a function in requests, but an attribute in the flask client:
    resp_dict = resp.json()

    assert resp_dict == {"foo": "bar"}