【发布时间】:2017-07-22 16:10:00
【问题描述】:
我正在尝试了解如何使用 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: Iterator 返回了一个非对象:'foobar'。
我需要做什么才能使 WebTest 文档中的示例代码运行?
【问题讨论】:
标签: python python-3.x webtest