提供fixture和marker的py.test插件可以简化异步tornado应用程序的测试。

pytest-tornado-yen3的Python项目详细描述


https://travis-ci.org/eugeniy/pytest-tornado.svg?branch=masterhttps://coveralls.io/repos/eugeniy/pytest-tornado/badge.svg

提供夹具和标记以简化测试的py.test插件 异步龙卷风的应用。

安装

pip install pytest-tornado

示例

importpytestimporttornado.webclassMainHandler(tornado.web.RequestHandler):defget(self):self.write("Hello, world")application=tornado.web.Application([(r"/",MainHandler),])@pytest.fixturedefapp():returnapplication@pytest.mark.gen_testdeftest_hello_world(http_client,base_url):response=yieldhttp_client.fetch(base_url)assertresponse.code==200

运行测试

py.test

固定装置

IO U回路
为每个测试用例创建tornado.ioloop.IOLoop的实例
HTTP端口
获取测试服务器使用的端口
基本URL
获取测试服务器的绝对基url, 例如,http://localhost:59828
HTTP服务器
启动tornado http服务器,必须创建appfixture, 返回要测试的tornado.web.Application
http_客户端
获取异步http客户端

显示插件提供的设备:

py.test --fixtures

标记

使用gen_test标记可以编写与 tornado.gen模块:

@pytest.mark.gen_testdeftest_tornado(http_client):response=yieldhttp_client.fetch('http://www.tornadoweb.org/')assertresponse.code==200

标记的测试将在5秒后超时。超时可以修改为 设置ASYNC_TEST_TIMEOUT环境变量, --async-test-timeout命令行参数或标记参数。

@pytest.mark.gen_test(timeout=5)deftest_tornado(http_client):yieldhttp_client.fetch('http://www.tornadoweb.org/')

标记还可以接收一个run_sync标志,如果关闭该标志,它将添加为协同程序并运行ioloop(直到超时),而不是同步运行测试。例如,这允许同时在客户机和服务器上测试东西。

@pytest.mark.gen_test(run_sync=False)deftest_tornado(http_server,http_client):response=yieldhttp_client.fetch('http://localhost:5555/my_local_server_test/')assertresponse.body=='Run on the same IOLoop!'

显示插件提供的标记:

py.test --markers

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java JavaFX 11可编辑组合框引发IndexOutOfBoundsException   java选择数组中的数组元素   java我从来没有找到创建2D ArrayList的正确方法   java JPA查找orderById的顶部数据,并按字符串过滤Id   使用java在ejabberd中进行xmpp外部身份验证   从ajax调用向java传递点运算符   java如何使用ReadWriteLock   使用Spring控制器和jQueryAjax的java重定向   java使JFrame中的JPanel可滚动   java如何用多个。jar库?   java EditText在RecyclerView中失去了对滚动的关注   java为什么我们必须扩展Servlet或GenericServlet或HttpServlet来创建Servlet应用程序?如果不扩展,我们可以开发Servlet应用程序吗?   使用递归java查找数组中的最大值   具有不同字段数的html表单的java域传输对象   java文本视图扩展;不支持操作异常   java如何使用iText的HTMLWorker类将多语言HTML字符串呈现为PDF