Я использую Python 2.7, Flask и unittest,
Я пытаюсь смоделировать сеанс, чтобы опубликовать запрос при входе в систему.
Вот что делают:
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)
и вот что я получаю
AssertionError: Popped wrong request context. (None instead of
<RequestContext 'http://localhost/' [GET] of flask_app>)
Я нашел это в stackoverflow
app.config['PRESERVE_CONTEXT_ON_EXCEPTION'] = False
Но это не работает
вот полный стек ошибок
======================================================================
FAIL: test_06_fill_form (__main__.BasicTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test.py", line 76, in test_06_fill_form
response = c.post('/thanks',data=datas)
File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/
contextlib.py",
line 35, in __exit__
self.gen.throw(type, value, traceback)
File "/Users/ymepa/work/Welcome.io/venv/lib/python2.7/site-
packages/flask/testing.py", line 164, in session_transaction
self.cookie_jar.extract_wsgi(c.request.environ, headers)
File "/Users/ymepa/work/Welcome.io/venv/lib/python2.7/site-
packages/flask/ctx.py", line 446, in __exit__
self.auto_pop(exc_value)
File "/Users/ymepa/work/Welcome.io/venv/lib/python2.7/site-
packages/flask/ctx.py", line 434, in auto_pop
self.pop(exc)
File "/Users/ymepa/work/Welcome.io/venv/lib/python2.7/site-
packages/flask/ctx.py", line 426, in pop
'(%r instead of %r)' % (rv, self)
AssertionError: Popped wrong request context. (None instead of
<RequestContext 'http://localhost/' [GET] of flask_app>)