我正在写一些pytest测试文件,这些文件附加到没有示例或步骤表的功能文件。我不明白的是,如何使用我的内联变量(USER1和USER2),这些变量是我的Given,When和Then步骤中的字符串(下面的简单示例),以便第一次执行'when'步骤时它使用John,然后第二次使用'when'步骤,它使用Peter。Pytest如何在步骤参数中使用内联变量?
我一直在阅读这些文档http://pytest-bdd.readthedocs.io/en/latest/#step-arguments及其说法使用解析器?也许我误解了这些文档,但是我不清楚如何执行下面的操作。也许用户需要在字典中? {'user1':'John','user2':'Peter'}。我明白,在功能文件中使用示例表或步骤表会很好,但在这种情况下,我需要知道如何在后台执行此操作(仅在pytest文件中)。
在此先感谢所有
USER1 = 'John'
USER2 = 'Peter'
@scenario('User logs in')
def test_user_logs_in():
"""User logs in to website."""
pass
@given('I go to a website')
def I_go_to_a_website():
Do something
@When('{user} logs in')
def user_logs_in(user):
Do something with user1 the first time this step is used
Do something with user2 the second time this step is used.
@then('I should see the account page')
def should_see_account_page():
Do something