我正在尝试理解如何使用WebTest进行集成测试,但我被第一个示例卡住了。
我试着按照指示去做。首先,我创建了一个包含要测试的代码的模块:
# functions.py
def application(environ, start_response):
"""docstring for application"""
# I added body, otherwise you get an undefined variable error
body = 'foobar'
headers = [('Content-Type', 'text/html; charset=utf8'),
('Content-Length', str(len(body)))]
start_response('200 OK', headers)
return [body]然后我创建了一个测试运行器文件:
# test.py
from webtest import TestApp
from functions import application
app = TestApp(application)
resp = app.get('/')
assert resp.status == '200 OK'
assert resp.status_int == 200当我执行test.py时,我得到以下错误:
AssertionError:迭代器返回了一个非对象:'foobar‘。
要运行WebTest文档中的示例代码,我需要做些什么?
发布于 2017-07-23 00:29:17
在WSGI中,主体必须是字节的可迭代:
body = b'foobar'https://stackoverflow.com/questions/45256603
复制相似问题