0
學習LearnPythonTheHardway的練習52時,我需要編寫用於web.py服務器的自動測試。 在app.py,我只是把功能:如何在測試代碼中基於web.py初始化會話?
app = web.application(urls, globals())
if web.config.get('_session') is None:
store = web.session.DiskStore('sessions')
init = {'room': None, 'count': 100}
session = web.session.Session(app, store, initializer=init)
web.config._session = session
else:
session = web.config._session
class count:
def GET(self):
print 'session', session
session.count += 1
return session.count
在app_test.py,我怎麼能初始化測試程序狀態的會話? 下面的代碼無法正常工作。該session.count不是51,我希望它是,但總是101
session.count = 50
resp = app.request("/count")
assert_equal(resp.data, "51")