提供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第三方库


热门话题
Android上已连接音频输入设备的java列表   java是创建类的新对象还是使用静态方法?   Java:Shift/Rotate对象数组   Java Casting ArrayIterator<Object>   在java中返回布尔值时出错   无法确定文本文件读入程序(java)中的各种元素   Java Swing JToolBar   JAVAlang.IllegalStateException执行Ghost4J(Linux 32对64位)   jvm如何增加ubuntu系统的java堆化?   java CORS策略“AccessControlAllowOrigin”(Anguar 8和Servlet)   使用dagger 2的java视图依赖项注入   单元测试中RxJava的java模拟活动生命周期   arraylist中的Java打印字符串   java返回值显示为0.0。为什么会这样?   java是clientserver应用程序所必需的MVC吗?   ByteToMessageDecoder类中的java内存泄漏   java将大量文档写入firestore   GWT项目中的java TomcatMaven插件。两者之间的区别是什么:org。科德豪斯。魔咒和组织。阿帕奇。公猫maven插件   java swing:向JTree项添加自定义图形按钮