Python3 安装Cucumber (behave)

0. 序言

Cucumber作为一个老牌的BDD框架,已经发展出各种语言的版本,Python下就有好几种,原先用的是最出名的Lettuce,但是之前Lettuce只支持Python2,不支持3。随着Python宣布2即将退役,Lettuce也宣布支持了Python3,然鹅笔者无数次安装还是无法正常运行,于是乎换了另一个Python的BDD框架behave

1. 安装

这里默认pip命令对应python3,然后就安装完成啦

pip install behave

或者

pip install git+https://github.com/behave/behave


我这里已经安装好了

2. 验证安装

在项目下创建一个feature文件夹,创建一个tutorial.feature文件,以及在feature文件夹下创建一个steps文件夹,用来存放feature对应的运行code,创建一个tutorial.py


把demo代码放进去

tutorial.feature

Feature: showing off behave

  Scenario: run a simple test

    Given we have behave installed

    When we implement a test

    Then behave will test it for us!

tutorial.py

from behave import *

@given('we have behave installed')

def step_impl(context):

    pass

@when('we implement a test')

def step_impl(context):

    assert True is not False

@then('behave will test it for us!')

def step_impl(context):

    assert context.failedis False

然后在项目目录下命令行运行behave,即可查看结果


参考文档

Behave Docs - Tutorial https://behave.readthedocs.io/en/latest/tutorial.html

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。