【发布时间】:2019-05-03 06:12:46
【问题描述】:
我想使用 pytest 为 web.py 应用程序编写单元测试。如何在 pytest 中调用 web.py 服务。
代码:
import web
urls = (
'/', 'index'
)
app = web.application(urls, globals())
class index:
def GET(self):
return "Hello, world!"
if __name__ == "__main__":
app.run()
可以使用python requests 模块来完成,当我们运行web.py服务时,它会运行http://localhost:8080/。然后导入 requests 模块并使用 get 方法,在响应对象中,您可以验证结果。没关系。
通过使用粘贴和鼻子,我们也可以按照 web.py 官方文档来实现这一点。 http://webpy.org/docs/0.3/tutorial.
pytest 中是否有类似 paste 和 nose 选项的解决方案。
【问题讨论】:
标签: python unit-testing pytest web.py