首页 > 解决方案 > python bdd框架:如何在步骤前后执行代码

问题描述

我很想在python中的一步之前和之后实现功能性

Scenario: Addition
        Given Calculator app is run
        When I input "2+3" to calculator
        Then I get result "5"

我希望在执行第二步之前执行一个功能。我该如何进行?

标签: python-3.xbddpython-behavepytest-bdd

解决方案


environment.py文件可用于:

features/environment.py

def before_step(context, step):
    if <some logic to determine which step this is>:
        do_something_before_step()

def after_step(context, step):
    if <some logic to determine which step this is>:
        do_something_after_step()

推荐阅读