我正在使用python 2.7,Flask和unittest, 我正在尝试模拟一个会话以在登录后发布请求。
这是做什么:
$products_count = 0;
foreach($store->products() as $product)
{
if($product->status == 1)
{
$products_count++;
}
}
dd($products_count);
这就是我得到的
def test_06_fill_form(self):
with self.app as c:
with c.session_transaction() as sess:
sess['user'] = 'yo'
datas={
"nom":"joe",
"prenom":"doe",
"company": "Google",
"email": "jdoe@joe.com",
"phone":"2343423"
}
print sess
self.assertTrue(sess.get('user') == 'yo')
response = c.post('/thanks',data=datas)
self.assertIn(b'Merci!', response.data)
我在stackoverflow上发现了
AssertionError: Popped wrong request context. (None instead of
<RequestContext 'http://localhost/' [GET] of flask_app>)
但这不起作用
这是一堆完整的错误
app.config['PRESERVE_CONTEXT_ON_EXCEPTION'] = False