pytest 的 fixture 其实是个依赖注入容器

最小例子

import pytest

@pytest.fixture
def client():
    app = create_app()
    with app.test_client() as c:
        yield c

def test_index(client):
    assert client.get("/").status_code == 200

scope

function(默认)、class、module、session,按启动成本选。