测试openerp modules的pytest插件
pytest-oerp的Python项目详细描述
py.test测试openerp modules的插件
用法
安装/更新方式:
pip install -U pytest-oerp
要运行测试,请键入:
py.test --oerp-server-path=<path to openerp server directory> \ --oerp-db=<db name, default is test>
这将使用~/.openerp_serverrc上的配置加载openerp,并为接收oerp属性的测试用例的choosen数据库创建一个池和事务。
编写测试
testcases只需要接收oerp就可以在oerps上创建事务,示例如下:
def test_simple(oerp): product_obj = oerp.pool.get('product.product') product_ids = product_obj.search(oerp.cr, 1, [])
这将运行在模块中类似openerp的代码中,您可以使用完整的openerp api。您只能从函数内部的openerp library加载内容,因为该库是动态添加到sys.path的。
OpenERP API
由于pytest oerps是在openerps中运行的,所以您需要在模块内完成的所有工作都可以在pytest oerp test中完成。通常的cr,uid属性是oerp.cr和1(这意味着第一个用户,通常是管理员)。oerp还有一个有用的pool属性。
待办事项
有很多抛光和功能需要完成,但暂定列表是:
- 支持将配置传递给OpenERP
- 更多的测试(总是一件好事)
- 不要依赖mock(很好的lib,但这可能是不必要的)
- 重定向打印日志
- pytest中的addini,以便您可以使用pytest.ini进行配置
- 生菜支持,但这可能会包含在另一个包中
注释
这个插件的官方存储库位于http://github.com/santagada/pytest-oerp
有关py.test的更多信息,请参见http://pytest.org
插件的所有工作都由proge(http://www.proge.com.br)赞助