安装notests和插件以简化bdd单元规范
specloud的Python项目详细描述
specloud
使用nosetest和插件来简化bdd规范。
安装
安装specloud最简单的方法是使用pip和需求文件:
$ pip install specloud
用法
获取一个带有bdd样式测试名称的python文件(以它开头、确保、应该、必须、规范、示例、deve),并将它们添加到测试套件中
例如:
$ cat example.py import unittest class CalculatorSpec(unittest.TestCase): def it_should_sum_integers(self): # ... pass def should_not_divide_by_zero(self): # ... pass def must_accept_floats(self): # ... pass def ensure_it_work_with_fractions(self): # ... pass def test_subtract_positive_from_negative_numbers(self): # ... pass def deve_calcular_raizes_quadradas(self): # ... pass
命令行工具specloud将green着色为没有失败和错误的测试,red着色为有失败和/或错误的测试:
$ specloud example.py Calculator spec - ensure it work with fractions - it should sum integers - must accept floats - should not divide by zero - subtract positive from negative numbers - deve calcular raizes quadradas ---------------------------------------------------------------------- Ran 6 tests in 0.003s OK
工作原理
specloud是一个python包,它安装了nose,pinocchio和figleaf包,因此它可以用pinocchio和figleaf插件调用nosetests。使用一些默认选项调用nosetests来查找测试方法,并使用pinocchio来显示漂亮的彩色消息。菲格里夫只是皮诺奇的依赖。
呼叫:
$ specloud FILE
做同样的事:
$ nosetests -i '^(it|ensure|must|should|specs?|examples?|deve)' -i '(specs?(.py)?|examples?(.py)?)$' '--with-spec' '--spec-color'
旧名
这个项目是作为一个概念的证明而诞生的,我首先将它命名为pyunitbdd。但那是个可怕的名字。所以我将项目重命名为specloud。