我正在尝试使用 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 令牌?