从Flask应用程序单元测试的设置(模拟)请求标头中找出我自己问题的答案。有一个environ_base
你可以通过请求环境变量为参数。它记录在werkzeug.test.EnvironBuilder中。
def test_insert_cash_flow_through_post(self): """Test that you can insert a cash flow through post.""" assert not CashFlow.query.first() self.client.post("/index?account=main", environ_base={'REMOTE_USER': 'foo'}, data=dict(settlement_date='01/01/2016', transaction_type='Other', certainty='Certain', transaction_amount=1)) assert CashFlow.query.first().user == 'foo'