基于stdlib单元测试的行为驱动开发(bdd)框架
python-specfor的Python项目详细描述
它的灵感来源于ruby的rspec。 规范定义基于python decorator描述。
功能
- 基于python decorator的“spec”定义
- “spec”定义与unittest.TestCase 兼容
- 规范文件可以使用unittest或nosetests 执行
- 类rspec期望(例如the[xxx].should.be[yyy])
- 基于decorator的“mock”对象定义
- 所有功能都可以独立使用:例如,使用spec和nose.tools
- 从规范文件中标记文档生成器
- 多python版本的单代码实现(2.5-2.7,3.1)
规范示例
# examples/sum_spec.py from specfor import the, spec empty_list = spec.of("empty list") int_list = spec.of("int list") @empty_list.before() def prepare(its): its.list = [] its.sum = 0 @int_list.before() def prepare(its): its.list = [2, 3, 5, 7, 11] its.sum = 28 @empty_list.that("sum") @int_list.that("sum") def sum_spec(its): result = sum(its.list) the[result].should == its.sum spec.publish(globals())
有关详细信息,请参见README.md