3

我想使用 pytest-bdd 编写一个类似小黄瓜的测试,为某些功能创建一组通用的测试数据。我不能使用给定添加多行,因为“给定步骤已被使用”。这样做的正确方法是什么?

我试过这个:

    Background:
        Given a user with Clerk privileges
        And a household entry for "Alice" with SubmissionDate "Nov 26, 2019 3:59:50 pm"
        And a household entry for "Bill" with SubmissionDate "Nov 27, 2019 3:59:50 pm"

这失败并显示以下消息:

E pytest_bdd.exceptions.GivenAlreadyUsed: 
Fixture "add_household" that implements this 
"a household entry for "Bill" with SubmissionDate "Nov 27, 2019 3:59:50 pm"" 
given step has been already used.
4

1 回答 1

1

嗨,您的 conftest.py 文件中的步骤定义是什么?

Background:Title
    Given something
    And something else
   And something more

在 conftest.py 中应该是

@given("something")
def something():
    # your code for something
    pass

@given("something else")
def something():
    # your code for something
    pass


@given("something more")
def something():
    # your code for something
    pass
于 2020-06-17T11:26:38.003 回答