我是Python和Behave的新手。我正在尝试为我的自动化项目设置POC。我遵循了行为文档中的教程,但是当我运行行为时,它会抛出无法检测到的步骤。我错过了什么?
我的文件夹结构如下所示。
from behave import given, when, then, step
@given(u'Launch GITHUB app with "{text}" and "{text}"')
def step_impl(context, user, password):
print(f"This is the given step with {user} and {password}")
要素文件
λ behave
Feature: Running sample feature # features/testone.feature:1
@smoke @regression
Scenario: Login to github and verify it works in testone feature of scenario one # features/testone.feature:4
Given Launch GITHUB app with "test@test.com" and "githubtest" # None
Failing scenarios:
features/testone.feature:4 Login to github and verify it works in testone feature of scenario one
0 features passed, 1 failed, 0 skipped
0 scenarios passed, 1 failed, 0 skipped
0 steps passed, 0 failed, 0 skipped, 1 undefined
Took 0m0.000s
You can implement step definitions for undefined steps with these snippets:
@given(u'Launch GITHUB app with "test@test.com" and "githubtest"')
def step_impl(context):
raise NotImplementedError(u'STEP: Given Launch GITHUB app with "test@test.com" and "githubtest"')
步骤文件
[pylint] E0611:No name 'given' in module 'behave'
[pylint] E0611:No name 'when' in module 'behave'
[pylint] E0611:No name 'then' in module 'behave'
[pylint] E0611:No name 'step' in module 'behave'
输出
patients_path = '..\data\external'
patients = os.listdir(vol_path)
print(volumes)
patient_path = os.path.join(patients_path, patients[0])
studies = os.listdir(patient_path)
print(studies)
idx = [s for s in np.arange(len(studies)) if not os.path.isdir(os.path.join(patient_path, studies[s]))]
for i in np.arange(len(idx)):
studies.remove(studies[idx[i]])
print(studies)
study_path = os.path.join(patient_path, studies[0])
print(study_path)
imageList = os.listdir(study_path)
print(imageList)
series_IDs = sitk.ImageSeriesReader.GetGDCMSeriesIDs(study_path)
print(series_IDs)
if not series_IDs:
print("ERROR: given directory \""+patient_path+"\" does not contain a DICOM series.")
sys.exit(1)
series_file_names = sitk.ImageSeriesReader.GetGDCMSeriesFileNames(patient_path, series_IDs[0])
series_reader = sitk.ImageSeriesReader()
series_reader.SetFileNames(series_file_names)
series_reader.MetaDataDictionaryArrayUpdateOn()
series_reader.LoadPrivateTagsOn()
image3D = series_reader.Execute()
我注意到在我的vscode编辑器中,在步骤文件中,pylint显示了此消息。
cts:element-word-query
答案 0 :(得分:1)
您的问题是您在步骤文件中使用了错误的格式。试试这个:
from behave import given, when, then, step
@given(u'Launch GITHUB app with "{user}" and "{password}"')
def step_impl(context, user, password):
print("This is the given step with {user} and {password}".format(user, password))
请注意,@given
语句中定义的参数与step_impl()
中传递的参数匹配。
即如果在@given
,你有
@given(u'Launch GITHUB app with "
{user} " and "
{密码} "')
然后在你的步骤实现中,你应该有
def step_impl(context,
的用户强> ,
的密码强> )
如果没有此匹配,并且在您当前的代码中,您将收到NotImplementedError
因为行为正在寻找步骤实施,其中context
和text
作为您的步骤中的参数文件,即def step_impl(context, text)
。