pyhistorian是一个bdd工具,用于使用给定的when-then模板编写规范
pyhistorian的Python项目详细描述
pyhistorian的目标是使用python编写给定的内部模板。 这些想法来自于jbehave、rbehave、cucumber和其他人。
你可以用英语和葡萄牙语写故事,选择你喜欢的。
下面是一个使用[en-us, by default]的好例子(调用这个文件calculator.py):
from should_dsl import * from pyhistorian import * class Calculator(object): def sum(self, n1, n2): return n1+n2 class SpecifyingMyNewCalculator(Story): """As a lazy mathematician I want to use a calculator So that I don't waste my time thinking""" colored = True template_color = 'yellow' scenarios = ['SumScenario'] # optional class SumScenario(Scenario): @Given('I have a calculator') def set_my_calculator(self): self.calculator = Calculator() @When('I enter with 1 + 1') def sum_one_to_one(self): self.result = self.calculator.sum(1, 1) @Then('I have $value as result', 2) def get_result(self, value): self.result |should_be| value if __name__ == '__main__': SpecifyingMyNewCalculator.run()
跑步:
$ python calculator.py Story: Specifying my new calculator As a lazy mathematician I want to use a calculator So that I don't waste my time thinking Scenario 1: Sum of 1 and 1 Given I have a calculator ... OK When I enter with 1 + 1 ... OK Then I have 2 as result ... OK Ran 1 scenarios with 0 failures, 0 errors and 0 pending steps