OpenERP的有用测试基类和工具
anybox.testing.openerp的Python项目详细描述
此发行版旨在提供测试工具,尤其是 单元测试基类,以增强OpenERP内置的基类 (版本>;=7)
目前,它具有以下基本测试类:
如何安装
一般来说,你只需要做anybox.testing.openerp 可从运行测试的python可执行文件导入。
Buildout recipe的用户只需添加 anybox.testing.openerp到他们的鸡蛋列表中,最好在 面向开发人员的构建配置:
[buildout] extends = buildout.cfg [openerp] eggs += anybox.testing.openerp
(当然,假设安装openerps的部分名为 openerp)
共享SetupTransactionCase
from anybox.testing.openerp import SharedSetupTransactionCase
这个类允许在测试类级别上进行交互。 测试数据准备,这样就不必再次执行 一次又一次。它在内部依赖postgresql保存点来实现这一点。
最简单的用法是加载一些xml文件:
class MyTestCase(SharedSetupTransactionCase): _data_files = ('employees.xml', 'products.xml') _module_ns = 'tests'
路径与保存测试python模块的目录相关 (通常是tests);_module_ns用于指定 (现有的或不存在的)OpenEP模块的命名空间,数据将是 插入。这是必要的,例如,在 one2many值。
您还可以将initTestData类作为子类 插入您自己准备的方法:
@classmethod def initTestData(cls): # if you need them XML data files: super(MyTestCase, cls).initTestData() cls.initLotsOfStuff()
最后,这个类配备了utility and assertion methods。
事务处理案例
from anybox.testing.openerp import TransactionCase
这是^{tt8}的一个简单子类$ 特点:
(仅在python>;=2.7上下文中)更健壮的tearDown 防止在setUp期间出现异常。
这种异常已经被证明会导致postgresql死锁, 这是头痛和时间损失的主要来源。
实用程序和断言方法
TransactionCase和SharedSetupTransactionCase功能 其他帮助程序方法。这些是
- ^{tt13}$
- ^{tt14}$
- ^{tt15}$
- ^{tt16}$
他们允许更直接的写作和更多的可读性。 查看docstrings以了解更多详细信息。这个文档应该 狮身人面像很快。
为什么要单独包装
我们(Anybox)非常愿意直接加入OpenERP核心,并且已经准备好了 将此作为适当的合并请求提交(因此涉及 我们自己的资源比以前多了一点)。
也就是说,单独打包的原因是:
- we don’t want to depend on actual inclusion in the core for our projects
- we need this to be available in v7 branch (current stable)
- we might want or need to stay ahead of whichever inclusions can occur in the future ; using a published version is more convenient for us than keeping track in our private VCSes.
为什么不加一个插件呢?
是否really希望看到单元测试的模块出现在 你的模块列表?
贡献
我们非常愿意捐款。毫不犹豫地叉出 在BitBucket repository上拉取请求
更改
1.3.1(2014-01-31)
- #2:如果read(cr, uid, id)返回,assertRecord的健壮性 一份清单。
1.3(2013-12-26)
- 添加了一个新的assertUniqueWithValues()实用程序,组合 searchUnique()与assertRecord一起使用可以节省更多的麻烦。
1.2(2013-11-07)
- 添加了一个新的assertNoRecord(model, domain)实用程序
1.1(2012-08-05)
- 添加了实用程序和断言方法
- 更正的文档
1.0(2012-07-13)
- 初始版本