要测试视图,我目前必须传递“测试请求上下文”才能对其进行测试。怎样做才能避免通过?
def test_fun(self):
with app.test_request_context() and app.app_context():
# within this block, current_app points to app.
print(current_app.name)
with pyodbc.connect(connectionString) as conn:
cursor = conn.cursor()
my_view()
#this is the view that I want to test
@app.route("/",methods=['GET','POST']
def my_view()
with app.test_request_context()#<-- Is this required??? without this I get RuntimeError-working outside of request context
'''
does something
'''
return render_template('my_template.html')