我正在尝试为以下功能设置 pytest-bdd 套件。
Feature: Tree
# BUILD TOP-DOWN
Scenario: Add properties to tree
Given a new tree is created with name default
When the name of the tree is asked for
Then default is returned
Run Code Online (Sandbox Code Playgroud)
由于某种原因,when尽管字符串看起来相同,但我的步骤未被识别:
from pytest_bdd import scenario, given, when, then
from models import Tree
@scenario("../features/Tree.feature", "Add properties to tree")
def test_tree():
pass
@given("a new tree is created with name default", target_fixture="tree")
def tree():
return Tree(name="default")
@when("the name of the tree is asked for")
def get_name(tree): …Run Code Online (Sandbox Code Playgroud) 我有以下步骤定义,这会导致错误,因为@given找不到夹具,即使它是在 中定义的target_fixture:
import pytest
from pytest_bdd import scenario, given, when, then, parsers
from admin import Admin
@scenario('../features/Admin.feature',
'register a new user')
def test_admin():
pass
@given('I\'m logged in as an admin at <host_name> with email <admin_email> and password <admin_password>', target_fixture="admin_login")
def admin_login(host_name, admin_email, admin_password):
admin = Admin(admin_email, admin_password)
admin.login(host_name)
# assert admin.status_code == 200
return admin
@when('I call the register method for host <host_name> with email <user_email> and password <user_password> and firstName <first_name> and last name <last_name>') …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过测试资源管理器在 VS Code 中运行我的行为场景。我的功能文件和步骤文件已正确绑定,因为同一个项目在 Pycharm 专业版(试用版)上运行。我没有看到我的测试资源管理器加载我的场景。我需要设置哪些配置?我是Python新手。我已经安装了以下支持行为的扩展。
下面是我的 launch.json
{
"python.testing.pytestArgs": [
"venv"
],
"python.testing.unittestEnabled": true,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": false,
"python.testing.unittestArgs": [
"-v",
"-s",
"./Tests",
"-p",
"*test.py"
]
}
Run Code Online (Sandbox Code Playgroud)
我想定义一个基于 PyTest-BDD 的场景大纲,其中包含多个示例。示例片段:
Scenario Outline: front to back validation
When tester executes access view sql query <sqlCommandProp> into av dataframe
And tester adds investment quant id to av dataframe
And tester reads raw file <fileNameProp> from datalake into raw dataframe
@raw2AccessValidation
Examples:
|sqlCommandProp|fileNameProp|
|sqlCommand | fileName |
@raw2AccessValidation2
Examples:
|sqlCommandProp|fileNameProp|
|eric | shane |
Run Code Online (Sandbox Code Playgroud)
我想为每个示例都有单独的标签,因为我可能不想运行所有示例。
我已经尝试了上面的方法,发现多个示例都可以。但是,我似乎无法识别不同的标签,因此我无法指定要运行这两个(或更多)中的哪一个。
我问是因为这可以用 java/cucumber 引擎完成。想知道我是否使用 pytest-bdd 遗漏了什么,做错了什么?
谢谢