步骤定义中传递的参数未读取并期望固定装置

问题描述 投票:0回答:1

pytest 8.3.2,pytest-bdd=7.2.0

这是我的功能文件:

Feature: Blog
    A site where you can publish your articles.

Scenario: Publishing the article
    Given "test" the application

以下是步骤定义文件。但是当我运行它时,我遇到了问题,因为找不到固定“短语”。不知道为什么它期望这里的固定装置。我现在不想拥有适合我的场景的固定装置。

scenario('../features/test_app.feature', 'Publishing the article')

@given(parsers.parse(" {phrase} the application"))
def test_app(phrase):
    print(phrase)

我希望函数中传递的参数应该被传递

python pytest pytest-bdd
1个回答
0
投票

当您运行

pytest
(安装或不安装
pytest-bdd
)时,它会执行以
test
开头的所有功能。步骤定义函数的名称是
test_app()
,因此它被选为普通(非 BDD)pytest 测试函数。

您所需要做的就是重命名该函数!

编辑:此外,在解析的句子开头有一个额外的空格 - 您需要将其删除才能正确匹配步骤定义。

© www.soinside.com 2019 - 2024. All rights reserved.