1
如何在烧瓶test_request_context中设置remote_addr
属性?这个问题:Get IP Address when testing flask application through nosetests(和其他类似问题)解释了如何使用get/post/whatever测试客户端调用来完成它,但我没有使用这些(在这种情况下)。相反,我得到一个test_request_context,然后调用一个函数,从而允许我单独测试由我的视图函数调用的函数。在烧瓶中设置remote_addr test_request_context
编辑:为了澄清,我的测试代码看起来是这样的:
with app.test_request_context():
result=my_function_which_expects_to_be_called_from_a_request_context()
<check result however>
所以在任何时候,我使用的测试客户端调用。