烧瓶 pytest 显示“CSRF 令牌丢失错误”

时间:2021-07-22 12:28:44

标签: python flask pytest csrf

我正在尝试使用 pytest 测试登录功能

这是我的设置:

@pytest.fixture
def client():
    app = create_app(TestConfig)
    with app.test_client() as client:
        with app.app_context():
            yield client
            db.session.remove()
            db.drop_all()

测试用例是:

client.post('/login', data=dict(
            username=username,
            password=password
    ), follow_redirects=True)

当我运行测试套件时,它返回错误 The CSRF token is missing.

如何在 post 请求中发送 CSRF 令牌?

0 个答案:

没有答案