bdd的pytest插件
pytest-eucalyptus的Python项目详细描述
Eucalyptus-Pytest的bdd插件
A nice fork of Aloe. Migrated from Nose to Pytest.
pytest eucalyptus已构建为具有两个世界的最佳特性:
- Aloe它实现了很好的基础结构并使用了原始的小黄瓜解析器。
快速启动
创建新模块并添加空的
__init__.py
。安装pytest和eucalyptus:
pip install pytest pytest-eucalyptus
假设我们正在测试
calculator.py
的以下实现:defadd(*numbers):returnsum(numbers)
编写第一个功能
tests/calculator.feature
:Feature: Add up numbers As a mathematically challenged user I want to add numbers So that I know the total Scenario: Add two numbers Given I have entered 50 into the calculator And I have entered 30 into the calculator When I press add Then the result should be 80 on the screen
在
中添加定义tests/conftest.py
:fromcalculatorimportaddfrompytest_eucalyptusimportbefore,step,world@before.each_exampledefclear(*args):"""Reset the calculator state before each scenario."""world.numbers=[]world.result=0@step(r'I have entered (\d+) into the calculator')defenter_number(self,number):world.numbers.append(float(number))@step(r'I press add')defpress_add(self):world.result=add(*world.numbers)@step(r'The result should be (\d+) on the screen')defassert_result(self,result):assertworld.result==float(result)
运行代码
$ pytest
============================= test session starts ==============================
platform darwin -- Python 3.7.3, pytest-4.6.3, py-1.8.0, pluggy-0.12.0
rootdir: /Users/eucalyptus-user/src/test
plugins: eucalyptus-0.3.0
collected 1 item
calculator.feature . [100%]
=========================== 1 passed in 0.01 seconds ===========================
文档
请查找更多文档here。
许可证
pytest eucalyptus是在apache许可证2.0下获得许可的,请参见LICENSE.md了解具体的详细信息。