pytest_bdd.exceptions.StepDefinitionNotFoundError 在 StepDefinition 中使用 parsers.re 时触发错误。
我使用了以下功能文件
Feature: Login Page
Scenario: Opening Login page and logging in
Given URL is created
When User is opening the login page and entering the details
Then User is logged in
Scenario: Opening Login page and registering
Given URL is created
When User is opening the login page and registering
Then User is logged in
对于步骤定义,我尝试使用如下所示的parsers.re来重用这些步骤。(场景,给定然后不粘贴以保持细节清晰)。
from pytest_bdd import scenario, given, when, then, parsers
import re
@when(parsers.re(r'User is opening the login page (?P<login_type>[a-zA-Z]+)'), converters = dict(login_type = str))
def login(login_type):
return logging_in("name", login_type)
但是,我遇到了以下错误。
request = <FixtureRequest for <Function 'login'>>
step = <pytest_bdd.feature.Step object at 0x103ddd128>
scenario = <pytest_bdd.feature.Scenario object at 0x103dcbf98>
encoding = 'utf-8'
def _find_step_function(request, step, scenario, encoding):
"""Match the step defined by the regular expression pattern.
:param request: PyTest request object.
:param step: Step.
:param scenario: Scenario.
:return: Function of the step.
:rtype: function
"""
name = step.name
try:
# Simple case where no parser is used for the step
return request.getfixturevalue(get_step_fixture_name(name, step.type, encoding))
except pytest_fixtures.FixtureLookupError:
try:
# Could not find a fixture with the same name, let's see if there is a parser involved
name = find_argumented_step_fixture_name(name, step.type, request._fixturemanager, request)
if name:
return request.getfixturevalue(name)
raise
except pytest_fixtures.FixtureLookupError:
raise exceptions.StepDefinitionNotFoundError(
u"""Step definition is not found: {step}."""
""" Line {step.line_number} in scenario "{scenario.name}" in the feature "{feature.filename}""".format(
step=step,
scenario=scenario,
> feature=scenario.feature,
)
)
E pytest_bdd.exceptions.StepDefinitionNotFoundError: Step definition is not found: When "User is opening the login page and entering the details". Line 8 in scenario "Opening Login page and logging in" in the feature "../Features/login.feature
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytest_bdd/scenario.py:98: StepDefinitionNotFoundError
========================== 1 failed in 29.21 seconds ===========================
解析器与 re 一起使用的方式是否有问题导致错误?